Bin Meng | be3f06b | 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 | 6e6f4ce | 2015-06-17 11:15:36 +0800 | [diff] [blame] | 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
Bin Meng | be3f06b | 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 | 6f192dd | 2016-08-19 01:23:26 +0200 | [diff] [blame] | 18 | struct cpuid_result res; |
Bin Meng | be3f06b | 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 | 6f192dd | 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 | be3f06b | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 26 | |
| 27 | return 0; |
| 28 | } |
| 29 | |
Alexander Graf | 94eaa79 | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 30 | int cpu_x86_get_vendor(struct udevice *dev, char *buf, int size) |
| 31 | { |
| 32 | const char *vendor = cpu_vendor_name(gd->arch.x86_vendor); |
| 33 | |
| 34 | if (size < (strlen(vendor) + 1)) |
| 35 | return -ENOSPC; |
| 36 | |
| 37 | strcpy(buf, vendor); |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
Bin Meng | be3f06b | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 42 | int cpu_x86_get_desc(struct udevice *dev, char *buf, int size) |
| 43 | { |
| 44 | if (size < CPU_MAX_NAME_LEN) |
| 45 | return -ENOSPC; |
| 46 | |
| 47 | cpu_get_name(buf); |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
Bin Meng | 6e6f4ce | 2015-06-17 11:15:36 +0800 | [diff] [blame] | 52 | static int cpu_x86_get_count(struct udevice *dev) |
| 53 | { |
| 54 | int node, cpu; |
| 55 | int num = 0; |
| 56 | |
| 57 | node = fdt_path_offset(gd->fdt_blob, "/cpus"); |
| 58 | if (node < 0) |
| 59 | return -ENOENT; |
| 60 | |
| 61 | for (cpu = fdt_first_subnode(gd->fdt_blob, node); |
| 62 | cpu >= 0; |
| 63 | cpu = fdt_next_subnode(gd->fdt_blob, cpu)) { |
| 64 | const char *device_type; |
| 65 | |
| 66 | device_type = fdt_getprop(gd->fdt_blob, cpu, |
| 67 | "device_type", NULL); |
| 68 | if (!device_type) |
| 69 | continue; |
| 70 | if (strcmp(device_type, "cpu") == 0) |
| 71 | num++; |
| 72 | } |
| 73 | |
| 74 | return num; |
| 75 | } |
| 76 | |
Bin Meng | be3f06b | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 77 | static const struct cpu_ops cpu_x86_ops = { |
| 78 | .get_desc = cpu_x86_get_desc, |
Bin Meng | 6e6f4ce | 2015-06-17 11:15:36 +0800 | [diff] [blame] | 79 | .get_count = cpu_x86_get_count, |
Alexander Graf | 94eaa79 | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 80 | .get_vendor = cpu_x86_get_vendor, |
Bin Meng | be3f06b | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | static const struct udevice_id cpu_x86_ids[] = { |
| 84 | { .compatible = "cpu-x86" }, |
| 85 | { } |
| 86 | }; |
| 87 | |
| 88 | U_BOOT_DRIVER(cpu_x86_drv) = { |
| 89 | .name = "cpu_x86", |
| 90 | .id = UCLASS_CPU, |
| 91 | .of_match = cpu_x86_ids, |
| 92 | .bind = cpu_x86_bind, |
| 93 | .ops = &cpu_x86_ops, |
| 94 | }; |