blob: 39004ee5f0f5f889362b440444abdc9a43171440 [file] [log] [blame]
Bin Meng12d41052015-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 Mengf967f9a2015-06-17 11:15:36 +080013DECLARE_GLOBAL_DATA_PTR;
14
Bin Meng12d41052015-06-12 14:52:20 +080015int cpu_x86_bind(struct udevice *dev)
16{
17 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
Alexander Graf00b4fc22016-08-19 01:23:26 +020018 struct cpuid_result res;
Bin Meng12d41052015-06-12 14:52:20 +080019
20 plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
21 "intel,apic-id", -1);
Alexander Graf00b4fc22016-08-19 01:23:26 +020022 plat->family = gd->arch.x86;
23 res = cpuid(1);
24 plat->id[0] = res.eax;
25 plat->id[1] = res.edx;
Bin Meng12d41052015-06-12 14:52:20 +080026
27 return 0;
28}
29
30int 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
Bin Mengf967f9a2015-06-17 11:15:36 +080040static 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
Bin Meng12d41052015-06-12 14:52:20 +080065static const struct cpu_ops cpu_x86_ops = {
66 .get_desc = cpu_x86_get_desc,
Bin Mengf967f9a2015-06-17 11:15:36 +080067 .get_count = cpu_x86_get_count,
Bin Meng12d41052015-06-12 14:52:20 +080068};
69
70static const struct udevice_id cpu_x86_ids[] = {
71 { .compatible = "cpu-x86" },
72 { }
73};
74
75U_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};