From 27802bb7b20656f0c4c083a301b9bd6af131a19c Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Sat, 14 May 2022 01:23:22 +0200 Subject: [PATCH] cpu/x86/mp_init.c: Use existing code to create cpu struct device Change-Id: I80baadd405b31d6be2fdbb894b0f4b7c775da6f8 Signed-off-by: Arthur Heymans Reviewed-on: https://review.coreboot.org/c/coreboot/+/64341 Tested-by: build bot (Jenkins) Reviewed-by: Jonathan Zhang Reviewed-by: Felix Held --- src/cpu/x86/mp_init.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/cpu/x86/mp_init.c b/src/cpu/x86/mp_init.c index febc30b9de..0e4a571e96 100644 --- a/src/cpu/x86/mp_init.c +++ b/src/cpu/x86/mp_init.c @@ -369,18 +369,9 @@ static int allocate_cpu_devices(struct bus *cpu_bus, struct mp_params *p) info = cpu_info(); for (i = 1; i < max_cpus; i++) { - struct device_path cpu_path; - struct device *new; - - /* Build the CPU device path */ - cpu_path.type = DEVICE_PATH_APIC; - /* Assuming linear APIC space allocation. AP will set its own APIC id in the ap_init() path above. */ - cpu_path.apic.apic_id = info->cpu->path.apic.apic_id + i; - - /* Allocate the new CPU device structure */ - new = alloc_find_dev(cpu_bus, &cpu_path); + struct device *new = add_cpu_device(cpu_bus, info->cpu->path.apic.apic_id + i, 1); if (new == NULL) { printk(BIOS_CRIT, "Could not allocate CPU device\n"); max_cpus--; @@ -532,7 +523,6 @@ static enum cb_err bsp_do_flight_plan(struct mp_params *mp_params) static enum cb_err init_bsp(struct bus *cpu_bus) { - struct device_path cpu_path; struct cpu_info *info; /* Print processor name */ @@ -543,13 +533,15 @@ static enum cb_err init_bsp(struct bus *cpu_bus) enable_lapic(); setup_lapic_interrupts(); - /* Set the device path of the boot CPU. */ - cpu_path.type = DEVICE_PATH_APIC; - cpu_path.apic.apic_id = lapicid(); + struct device *bsp = add_cpu_device(cpu_bus, lapicid(), 1); + if (bsp == NULL) { + printk(BIOS_CRIT, "Failed to find or allocate BSP struct device\n"); + return CB_ERR; + } /* Find the device structure for the boot CPU. */ info = cpu_info(); - info->cpu = alloc_find_dev(cpu_bus, &cpu_path); + info->cpu = bsp; info->cpu->name = processor_name; if (info->index != 0) {