blob: be28ff64dce14f4decabc55931aefc8c1b3bc029 [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;
Arthur Heymans21ca7752022-05-14 02:14:31 +020016 cpu_path.apic.initial_lapicid = apic_id;
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +030017
18 /* Update CPU in devicetree. */
19 if (enabled)
20 cpu = alloc_find_dev(cpu_bus, &cpu_path);
21 else
22 cpu = find_dev_path(cpu_bus, &cpu_path);
23 if (!cpu)
24 return NULL;
25
26 cpu->enabled = enabled;
27 printk(BIOS_DEBUG, "CPU: %s %s\n",
28 dev_path(cpu), cpu->enabled?"enabled":"disabled");
29
30 return cpu;
31}