blob: f406e23f89f4bd6975a9129c404c8c3ce8292e2b [file] [log] [blame]
Angel Ponsc74dae92020-04-02 23:48:16 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03002
3#include <device/device.h>
4#include <console/console.h>
Elyes Haouas04c3b5a2022-10-07 10:08:05 +02005#include <stddef.h>
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03006
Elyes HAOUAS8cf8a632019-06-09 10:23:25 +02007struct device *add_cpu_device(struct bus *cpu_bus, unsigned int apic_id,
Elyes HAOUASe3480662018-05-06 20:32:23 +02008 int enabled)
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03009{
Arthur Heymans4f2b5a52022-11-17 20:36:40 +010010 struct device_path cpu_path = {};
Elyes HAOUASe3480662018-05-06 20:32:23 +020011 struct device *cpu;
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +030012
Elyes HAOUASfa640a22016-07-28 21:31:40 +020013 /* Build the CPU device path */
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +030014 cpu_path.type = DEVICE_PATH_APIC;
15 cpu_path.apic.apic_id = apic_id;
16
17 /* Update CPU in devicetree. */
18 if (enabled)
19 cpu = alloc_find_dev(cpu_bus, &cpu_path);
20 else
21 cpu = find_dev_path(cpu_bus, &cpu_path);
22 if (!cpu)
23 return NULL;
24
25 cpu->enabled = enabled;
26 printk(BIOS_DEBUG, "CPU: %s %s\n",
27 dev_path(cpu), cpu->enabled?"enabled":"disabled");
28
29 return cpu;
30}
31
Elyes HAOUAS8cf8a632019-06-09 10:23:25 +020032void set_cpu_topology(struct device *cpu, unsigned int node,
33 unsigned int package, unsigned int core,
34 unsigned int thread)
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +030035{
36 cpu->path.apic.node_id = node;
37 cpu->path.apic.package_id = package;
38 cpu->path.apic.core_id = core;
39 cpu->path.apic.thread_id = thread;
40}