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