include/device: ensure valid link/bus is passed to mp_cpu_bus_init

When a chipset or mainboard devicetree doesn't have any LAPIC devices in
its CPU cluster, not only the LAPIC device, but also the link/bus
between the CPU cluster device and the LAPIC devices will be missing and
the CPU cluster's dev->link_list will be NULL. This patch handles this
case in the common code like
commit 3c0ecd57c174b7391c66d22406effe18ce570cac (soc/intel/common/cpu:
Handle non-zero BSP APIC ID in init_cpus) and
commit ba936ce5db819d5ecb34e83a998b2390ecbdc4b9 (soc/intel/denverton_ns:
Ensure CPU device has a valid link) already did in the common Intel SoC
and the Denverton code. With this change all CPUs and SoC that use the
common mp_cpu_bus_init as init function in the CPU cluster's device
operations struct won't require having at least one LAPIC device in the
chipset or mainboard device tree.

Signed-off-by: Felix Held <felix-coreboot@felixheld.de>
Change-Id: Ib0d85de5cafb6390b8fbd512186899d6a815e972
Reviewed-on: https://review.coreboot.org/c/coreboot/+/58508
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Raul Rangel <rrangel@chromium.org>
diff --git a/src/include/device/device.h b/src/include/device/device.h
index 6bd6e0e..8610e0a 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -228,6 +228,17 @@
 void mp_init_cpus(DEVTREE_CONST struct bus *cpu_bus);
 static inline void mp_cpu_bus_init(struct device *dev)
 {
+	/*
+	 * When no LAPIC device is specified in the devietree inside the CPU cluster device,
+	 * neither a LAPIC device nor the link/bus between the CPU cluster and the LAPIC device
+	 * will be present in the static device tree and the link_list struct element of the
+	 * CPU cluster device will be NULL. In this case add one link, so that the
+	 * alloc_find_dev calls in init_bsp and allocate_cpu_devices will be able to add a
+	 * LAPIC device for the BSP and the APs on this link/bus.
+	 */
+	if (!dev->link_list)
+		add_more_links(dev, 1);
+
 	mp_init_cpus(dev->link_list);
 }