]> git.sur5r.net Git - u-boot/blob - arch/x86/cpu/cpu_x86.c
cpu: Add DMTF id and family fields
[u-boot] / arch / x86 / cpu / cpu_x86.c
1 /*
2  * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <cpu.h>
9 #include <dm.h>
10 #include <errno.h>
11 #include <asm/cpu.h>
12
13 DECLARE_GLOBAL_DATA_PTR;
14
15 int cpu_x86_bind(struct udevice *dev)
16 {
17         struct cpu_platdata *plat = dev_get_parent_platdata(dev);
18         struct cpuid_result res;
19
20         plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
21                                       "intel,apic-id", -1);
22         plat->family = gd->arch.x86;
23         res = cpuid(1);
24         plat->id[0] = res.eax;
25         plat->id[1] = res.edx;
26
27         return 0;
28 }
29
30 int cpu_x86_get_desc(struct udevice *dev, char *buf, int size)
31 {
32         if (size < CPU_MAX_NAME_LEN)
33                 return -ENOSPC;
34
35         cpu_get_name(buf);
36
37         return 0;
38 }
39
40 static int cpu_x86_get_count(struct udevice *dev)
41 {
42         int node, cpu;
43         int num = 0;
44
45         node = fdt_path_offset(gd->fdt_blob, "/cpus");
46         if (node < 0)
47                 return -ENOENT;
48
49         for (cpu = fdt_first_subnode(gd->fdt_blob, node);
50              cpu >= 0;
51              cpu = fdt_next_subnode(gd->fdt_blob, cpu)) {
52                 const char *device_type;
53
54                 device_type = fdt_getprop(gd->fdt_blob, cpu,
55                                           "device_type", NULL);
56                 if (!device_type)
57                         continue;
58                 if (strcmp(device_type, "cpu") == 0)
59                         num++;
60         }
61
62         return num;
63 }
64
65 static const struct cpu_ops cpu_x86_ops = {
66         .get_desc       = cpu_x86_get_desc,
67         .get_count      = cpu_x86_get_count,
68 };
69
70 static const struct udevice_id cpu_x86_ids[] = {
71         { .compatible = "cpu-x86" },
72         { }
73 };
74
75 U_BOOT_DRIVER(cpu_x86_drv) = {
76         .name           = "cpu_x86",
77         .id             = UCLASS_CPU,
78         .of_match       = cpu_x86_ids,
79         .bind           = cpu_x86_bind,
80         .ops            = &cpu_x86_ops,
81 };