xref: /aosp_15_r20/external/coreboot/src/device/cpu_device.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/device.h>
4 #include <console/console.h>
5 #include <stddef.h>
6 
add_cpu_device(struct bus * cpu_bus,unsigned int apic_id,int enabled)7 struct device *add_cpu_device(struct bus *cpu_bus, unsigned int apic_id,
8 			      int enabled)
9 {
10 	struct device_path cpu_path = {};
11 	struct device *cpu;
12 
13 	/* Build the CPU device path */
14 	cpu_path.type = DEVICE_PATH_APIC;
15 	cpu_path.apic.apic_id = apic_id;
16 	cpu_path.apic.initial_lapicid = apic_id;
17 
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 }
32