x86: ivybridge: Use syscon for the GMA device
[platform/kernel/u-boot.git] / common / cmd_cpu.c
1 /*
2  * Copyright (c) 2015 Google, Inc
3  * Written by Simon Glass <sjg@chromium.org>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <command.h>
10 #include <cpu.h>
11 #include <dm.h>
12 #include <errno.h>
13
14 static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
15         "L1 cache",
16         "MMU",
17 };
18
19 static int print_cpu_list(bool detail)
20 {
21         struct udevice *dev;
22         struct uclass *uc;
23         char buf[100];
24         int ret;
25
26         ret = uclass_get(UCLASS_CPU, &uc);
27         if (ret) {
28                 printf("Cannot find CPU uclass\n");
29                 return ret;
30         }
31         uclass_foreach_dev(dev, uc) {
32                 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
33                 struct cpu_info info;
34                 bool first;
35                 int i;
36
37                 ret = cpu_get_desc(dev, buf, sizeof(buf));
38                 printf("%3d: %-10s %s\n", dev->seq, dev->name,
39                        ret ? "<no description>" : buf);
40                 if (!detail)
41                         continue;
42                 ret = cpu_get_info(dev, &info);
43                 if (ret) {
44                         printf("\t(no detail available");
45                         if (ret != -ENOSYS)
46                                 printf(": err=%d\n", ret);
47                         printf(")\n");
48                         continue;
49                 }
50                 printf("\tID = %d, freq = ", plat->cpu_id);
51                 print_freq(info.cpu_freq, "");
52                 first = true;
53                 for (i = 0; i < CPU_FEAT_COUNT; i++) {
54                         if (info.features & (1 << i)) {
55                                 printf("%s%s", first ? ": " : ", ",
56                                        cpu_feature_name[i]);
57                                 first = false;
58                         }
59                 }
60                 printf("\n");
61         }
62
63         return 0;
64 }
65
66 static int do_cpu_list(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
67 {
68         if (print_cpu_list(false))
69                 return CMD_RET_FAILURE;
70
71         return 0;
72 }
73
74 static int do_cpu_detail(cmd_tbl_t *cmdtp, int flag, int argc,
75                          char *const argv[])
76 {
77         if (print_cpu_list(true))
78                 return CMD_RET_FAILURE;
79
80         return 0;
81 }
82
83 static cmd_tbl_t cmd_cpu_sub[] = {
84         U_BOOT_CMD_MKENT(list, 2, 1, do_cpu_list, "", ""),
85         U_BOOT_CMD_MKENT(detail, 4, 0, do_cpu_detail, "", ""),
86 };
87
88 /*
89  * Process a cpu sub-command
90  */
91 static int do_cpu(cmd_tbl_t *cmdtp, int flag, int argc,
92                        char * const argv[])
93 {
94         cmd_tbl_t *c = NULL;
95
96         /* Strip off leading 'cpu' command argument */
97         argc--;
98         argv++;
99
100         if (argc)
101                 c = find_cmd_tbl(argv[0], cmd_cpu_sub, ARRAY_SIZE(cmd_cpu_sub));
102
103         if (c)
104                 return c->cmd(cmdtp, flag, argc, argv);
105         else
106                 return CMD_RET_USAGE;
107 }
108
109 U_BOOT_CMD(
110         cpu, 2, 1, do_cpu,
111         "display information about CPUs",
112         "list   - list available CPUs\n"
113         "cpu detail     - show CPU detail"
114 );