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); |
| 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 | |
| 25 | int 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 Meng | f967f9a | 2015-06-17 11:15:36 +0800 | [diff] [blame] | 35 | static 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 Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 60 | static const struct cpu_ops cpu_x86_ops = { |
| 61 | .get_desc = cpu_x86_get_desc, |
Bin Meng | f967f9a | 2015-06-17 11:15:36 +0800 | [diff] [blame] | 62 | .get_count = cpu_x86_get_count, |
Bin Meng | 12d4105 | 2015-06-12 14:52:20 +0800 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | static const struct udevice_id cpu_x86_ids[] = { |
| 66 | { .compatible = "cpu-x86" }, |
| 67 | { } |
| 68 | }; |
| 69 | |
| 70 | U_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 | }; |