Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 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 | |
Bin Meng | f967f9a | 2015-06-17 11:15:36 +0800 | [diff] [blame] | 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 15 | int cpu_x86_bind(struct udevice *dev) |
| 16 | { |
| 17 | struct cpu_platdata *plat = dev_get_parent_platdata(dev); |
Alexander Graf | 00b4fc2 | 2016-08-19 01:23:26 +0200 | [diff] [blame^] | 18 | struct cpuid_result res; |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 19 | |
| 20 | plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev->of_offset, |
| 21 | "intel,apic-id", -1); |
Alexander Graf | 00b4fc2 | 2016-08-19 01:23:26 +0200 | [diff] [blame^] | 22 | plat->family = gd->arch.x86; |
| 23 | res = cpuid(1); |
| 24 | plat->id[0] = res.eax; |
| 25 | plat->id[1] = res.edx; |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 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 | |
Bin Meng | f967f9a | 2015-06-17 11:15:36 +0800 | [diff] [blame] | 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 | |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 65 | static const struct cpu_ops cpu_x86_ops = { |
| 66 | .get_desc = cpu_x86_get_desc, |
Bin Meng | f967f9a | 2015-06-17 11:15:36 +0800 | [diff] [blame] | 67 | .get_count = cpu_x86_get_count, |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 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 | }; |