summaryrefslogtreecommitdiff
path: root/cmd/cpu.c
blob: ff553c16c4e4107125bde4785b8ca906dda59891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (c) 2015 Google, Inc
 * Written by Simon Glass <sjg@chromium.org>
 * Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
 */

#include <common.h>
#include <command.h>
#include <cpu.h>
#include <dm.h>
#include <errno.h>

static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
	"L1 cache",
	"MMU",
	"Microcode",
	"Device ID",
};

static int print_cpu_list(bool detail)
{
	struct udevice *dev;
	char buf[100];

	for (uclass_first_device(UCLASS_CPU, &dev);
		     dev;
		     uclass_next_device(&dev)) {
		struct cpu_platdata *plat = dev_get_parent_platdata(dev);
		struct cpu_info info;
		bool first = true;
		int ret, i;

		ret = cpu_get_desc(dev, buf, sizeof(buf));
		printf("%3d: %-10s %s\n", dev->seq, dev->name,
		       ret ? "<no description>" : buf);
		if (!detail)
			continue;
		ret = cpu_get_info(dev, &info);
		if (ret) {
			printf("\t(no detail available");
			if (ret != -ENOSYS)
				printf(": err=%d", ret);
			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");
		if (info.features & (1 << CPU_FEAT_UCODE))
			printf("\tMicrocode version %#x\n",
			       plat->ucode_version);
		if (info.features & (1 << CPU_FEAT_DEVICE_ID))
			printf("\tDevice ID %#lx\n", plat->device_id);
	}

	return 0;
}

static int do_cpu_list(struct cmd_tbl *cmdtp, int flag, int argc,
		       char *const argv[])
{
	if (print_cpu_list(false))
		return CMD_RET_FAILURE;

	return 0;
}

static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc,
			 char *const argv[])
{
	if (print_cpu_list(true))
		return CMD_RET_FAILURE;

	return 0;
}

static struct cmd_tbl cmd_cpu_sub[] = {
	U_BOOT_CMD_MKENT(list, 2, 1, do_cpu_list, "", ""),
	U_BOOT_CMD_MKENT(detail, 4, 0, do_cpu_detail, "", ""),
};

/*
 * Process a cpu sub-command
 */
static int do_cpu(struct cmd_tbl *cmdtp, int flag, int argc,
		  char *const argv[])
{
	struct cmd_tbl *c = NULL;

	/* Strip off leading 'cpu' command argument */
	argc--;
	argv++;

	if (argc)
		c = find_cmd_tbl(argv[0], cmd_cpu_sub,
				 ARRAY_SIZE(cmd_cpu_sub));

	if (c)
		return c->cmd(cmdtp, flag, argc, argv);
	else
		return CMD_RET_USAGE;
}

U_BOOT_CMD(
	cpu, 2, 1, do_cpu,
	"display information about CPUs",
	"list	- list available CPUs\n"
	"cpu detail	- show CPU detail"
);