Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <cpu.h> |
| 8 | #include <dm.h> |
| 9 | #include <errno.h> |
| 10 | #include <asm/cpu.h> |
| 11 | |
Bin Meng | f967f9a | 2015-06-17 11:15:36 +0800 | [diff] [blame] | 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 14 | int cpu_x86_bind(struct udevice *dev) |
| 15 | { |
| 16 | struct cpu_platdata *plat = dev_get_parent_platdata(dev); |
Alexander Graf | 00b4fc2 | 2016-08-19 01:23:26 +0200 | [diff] [blame] | 17 | struct cpuid_result res; |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 18 | |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 19 | plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 20 | "intel,apic-id", -1); |
Alexander Graf | 00b4fc2 | 2016-08-19 01:23:26 +0200 | [diff] [blame] | 21 | plat->family = gd->arch.x86; |
| 22 | res = cpuid(1); |
| 23 | plat->id[0] = res.eax; |
| 24 | plat->id[1] = res.edx; |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 25 | |
| 26 | return 0; |
| 27 | } |
| 28 | |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 29 | int cpu_x86_get_vendor(struct udevice *dev, char *buf, int size) |
| 30 | { |
| 31 | const char *vendor = cpu_vendor_name(gd->arch.x86_vendor); |
| 32 | |
| 33 | if (size < (strlen(vendor) + 1)) |
| 34 | return -ENOSPC; |
| 35 | |
| 36 | strcpy(buf, vendor); |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 41 | int cpu_x86_get_desc(struct udevice *dev, char *buf, int size) |
| 42 | { |
Simon Glass | 0bd50cd | 2017-03-19 12:59:20 -0600 | [diff] [blame] | 43 | char *ptr; |
| 44 | |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 45 | if (size < CPU_MAX_NAME_LEN) |
| 46 | return -ENOSPC; |
| 47 | |
Simon Glass | 0bd50cd | 2017-03-19 12:59:20 -0600 | [diff] [blame] | 48 | ptr = cpu_get_name(buf); |
| 49 | if (ptr != buf) |
| 50 | strcpy(buf, ptr); |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
Wolfgang Wallner | b965558 | 2020-02-25 13:19:47 +0100 | [diff] [blame] | 55 | int cpu_x86_get_count(struct udevice *dev) |
Bin Meng | f967f9a | 2015-06-17 11:15:36 +0800 | [diff] [blame] | 56 | { |
| 57 | int node, cpu; |
| 58 | int num = 0; |
| 59 | |
| 60 | node = fdt_path_offset(gd->fdt_blob, "/cpus"); |
| 61 | if (node < 0) |
| 62 | return -ENOENT; |
| 63 | |
| 64 | for (cpu = fdt_first_subnode(gd->fdt_blob, node); |
| 65 | cpu >= 0; |
| 66 | cpu = fdt_next_subnode(gd->fdt_blob, cpu)) { |
| 67 | const char *device_type; |
| 68 | |
| 69 | device_type = fdt_getprop(gd->fdt_blob, cpu, |
| 70 | "device_type", NULL); |
| 71 | if (!device_type) |
| 72 | continue; |
| 73 | if (strcmp(device_type, "cpu") == 0) |
| 74 | num++; |
| 75 | } |
| 76 | |
| 77 | return num; |
| 78 | } |
| 79 | |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 80 | static const struct cpu_ops cpu_x86_ops = { |
| 81 | .get_desc = cpu_x86_get_desc, |
Bin Meng | f967f9a | 2015-06-17 11:15:36 +0800 | [diff] [blame] | 82 | .get_count = cpu_x86_get_count, |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 83 | .get_vendor = cpu_x86_get_vendor, |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | static const struct udevice_id cpu_x86_ids[] = { |
| 87 | { .compatible = "cpu-x86" }, |
| 88 | { } |
| 89 | }; |
| 90 | |
| 91 | U_BOOT_DRIVER(cpu_x86_drv) = { |
| 92 | .name = "cpu_x86", |
| 93 | .id = UCLASS_CPU, |
| 94 | .of_match = cpu_x86_ids, |
| 95 | .bind = cpu_x86_bind, |
| 96 | .ops = &cpu_x86_ops, |
Bin Meng | 09921ac | 2018-10-14 01:07:19 -0700 | [diff] [blame] | 97 | .flags = DM_FLAG_PRE_RELOC, |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 98 | }; |