// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
 */

#include <cpu.h>
#include <dm.h>
#include <errno.h>
#include <asm/cpu.h>
#include <asm/global_data.h>

DECLARE_GLOBAL_DATA_PTR;

int cpu_x86_bind(struct udevice *dev)
{
	struct cpu_plat *plat = dev_get_parent_plat(dev);
	struct cpuid_result res;

	plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
				      "intel,apic-id", -1);
	plat->family = gd->arch.x86;
	res = cpuid(1);
	plat->id[0] = res.eax;
	plat->id[1] = res.edx;

	return 0;
}

int cpu_x86_get_vendor(const struct udevice *dev, char *buf, int size)
{
	const char *vendor = cpu_vendor_name(gd->arch.x86_vendor);

	if (size < (strlen(vendor) + 1))
		return -ENOSPC;

	strcpy(buf, vendor);

	return 0;
}

int cpu_x86_get_desc(const struct udevice *dev, char *buf, int size)
{
	char *ptr;

	if (size < CPU_MAX_NAME_LEN)
		return -ENOSPC;

	ptr = cpu_get_name(buf);
	if (ptr != buf)
		strcpy(buf, ptr);

	return 0;
}

int cpu_x86_get_count(const struct udevice *dev)
{
	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;
}

static const struct cpu_ops cpu_x86_ops = {
	.get_desc	= cpu_x86_get_desc,
	.get_count	= cpu_x86_get_count,
	.get_vendor	= cpu_x86_get_vendor,
};

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,
	.flags		= DM_FLAG_PRE_RELOC,
};
