blob: 09410416a1ff07aee6698adc94165f37af958fa5 [file] [log] [blame]
Bin Mengbe3f06b2015-06-12 14:52:20 +08001/*
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
Bin Meng6e6f4ce2015-06-17 11:15:36 +080013DECLARE_GLOBAL_DATA_PTR;
14
Bin Mengbe3f06b2015-06-12 14:52:20 +080015int 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
Bin Meng6e6f4ce2015-06-17 11:15:36 +080035static 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
Bin Mengbe3f06b2015-06-12 14:52:20 +080060static const struct cpu_ops cpu_x86_ops = {
61 .get_desc = cpu_x86_get_desc,
Bin Meng6e6f4ce2015-06-17 11:15:36 +080062 .get_count = cpu_x86_get_count,
Bin Mengbe3f06b2015-06-12 14:52:20 +080063};
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};