2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-06-12 06:52:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <cpu.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <asm/cpu.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2015-06-12 06:52:20 +00:00
|
|
|
|
2015-06-17 03:15:36 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2015-06-12 06:52:20 +00:00
|
|
|
int cpu_x86_bind(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct cpu_plat *plat = dev_get_parent_plat(dev);
|
2016-08-18 23:23:26 +00:00
|
|
|
struct cpuid_result res;
|
2015-06-12 06:52:20 +00:00
|
|
|
|
2017-01-17 23:52:55 +00:00
|
|
|
plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
|
2015-06-12 06:52:20 +00:00
|
|
|
"intel,apic-id", -1);
|
2016-08-18 23:23:26 +00:00
|
|
|
plat->family = gd->arch.x86;
|
|
|
|
res = cpuid(1);
|
|
|
|
plat->id[0] = res.eax;
|
|
|
|
plat->id[1] = res.edx;
|
2015-06-12 06:52:20 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-27 05:06:27 +00:00
|
|
|
int cpu_x86_get_vendor(const struct udevice *dev, char *buf, int size)
|
2016-08-18 23:23:27 +00:00
|
|
|
{
|
|
|
|
const char *vendor = cpu_vendor_name(gd->arch.x86_vendor);
|
|
|
|
|
|
|
|
if (size < (strlen(vendor) + 1))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
strcpy(buf, vendor);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-27 05:06:27 +00:00
|
|
|
int cpu_x86_get_desc(const struct udevice *dev, char *buf, int size)
|
2015-06-12 06:52:20 +00:00
|
|
|
{
|
2017-03-19 18:59:20 +00:00
|
|
|
char *ptr;
|
|
|
|
|
2015-06-12 06:52:20 +00:00
|
|
|
if (size < CPU_MAX_NAME_LEN)
|
|
|
|
return -ENOSPC;
|
|
|
|
|
2017-03-19 18:59:20 +00:00
|
|
|
ptr = cpu_get_name(buf);
|
|
|
|
if (ptr != buf)
|
|
|
|
strcpy(buf, ptr);
|
2015-06-12 06:52:20 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-27 05:06:27 +00:00
|
|
|
int cpu_x86_get_count(const struct udevice *dev)
|
2015-06-17 03:15:36 +00:00
|
|
|
{
|
|
|
|
int node, cpu;
|
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
node = fdt_path_offset(gd->fdt_blob, "/cpus");
|
|
|
|
if (node < 0)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
for (cpu = fdt_first_subnode(gd->fdt_blob, node);
|
|
|
|
cpu >= 0;
|
|
|
|
cpu = fdt_next_subnode(gd->fdt_blob, cpu)) {
|
|
|
|
const char *device_type;
|
|
|
|
|
|
|
|
device_type = fdt_getprop(gd->fdt_blob, cpu,
|
|
|
|
"device_type", NULL);
|
|
|
|
if (!device_type)
|
|
|
|
continue;
|
|
|
|
if (strcmp(device_type, "cpu") == 0)
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2015-06-12 06:52:20 +00:00
|
|
|
static const struct cpu_ops cpu_x86_ops = {
|
|
|
|
.get_desc = cpu_x86_get_desc,
|
2015-06-17 03:15:36 +00:00
|
|
|
.get_count = cpu_x86_get_count,
|
2016-08-18 23:23:27 +00:00
|
|
|
.get_vendor = cpu_x86_get_vendor,
|
2015-06-12 06:52:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id cpu_x86_ids[] = {
|
|
|
|
{ .compatible = "cpu-x86" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(cpu_x86_drv) = {
|
|
|
|
.name = "cpu_x86",
|
|
|
|
.id = UCLASS_CPU,
|
|
|
|
.of_match = cpu_x86_ids,
|
|
|
|
.bind = cpu_x86_bind,
|
|
|
|
.ops = &cpu_x86_ops,
|
2018-10-14 08:07:19 +00:00
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
2015-06-12 06:52:20 +00:00
|
|
|
};
|