x86: Move qemu CPU fixup function into its own file
[oweals/u-boot.git] / arch / x86 / cpu / mp_init.c
index 988073cc7953f188cf1ffc7758263df83934b437..7b09f90cd518e449cd59635bdc996429cf1b0700 100644 (file)
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2015 Google, Inc
  *
- * SPDX-License-Identifier:    GPL-2.0+
- *
  * Based on code from the coreboot file of the same name
  */
 
@@ -248,7 +247,8 @@ static int load_sipi_vector(atomic_t **ap_countp, int num_cpus)
        if (!stack)
                return -ENOMEM;
        params->stack_top = (u32)(stack + size);
-#if !defined(CONFIG_QEMU) && !defined(CONFIG_HAVE_FSP)
+#if !defined(CONFIG_QEMU) && !defined(CONFIG_HAVE_FSP) && \
+       !defined(CONFIG_INTEL_MID)
        params->microcode_ptr = ucode_base;
        debug("Microcode at %x\n", params->microcode_ptr);
 #endif
@@ -322,7 +322,7 @@ static int start_aps(int ap_count, atomic_t *num_aps)
        if (sipi_vector > max_vector_loc) {
                printf("SIPI vector too large! 0x%08x\n",
                       sipi_vector);
-               return -1;
+               return -ENOSPC;
        }
 
        debug("Attempting to start %d APs\n", ap_count);
@@ -364,7 +364,7 @@ static int start_aps(int ap_count, atomic_t *num_aps)
        if (wait_for_aps(num_aps, ap_count, 10000, 50)) {
                debug("Not all APs checked in: %d/%d\n",
                      atomic_read(num_aps), ap_count);
-               return -1;
+               return -EIO;
        }
 
        return 0;
@@ -387,7 +387,7 @@ static int bsp_do_flight_plan(struct udevice *cpu, struct mp_params *mp_params)
                        if (wait_for_aps(&rec->cpus_entered, num_aps,
                                         timeout_us, step_us)) {
                                debug("MP record %d timeout\n", i);
-                               ret = -1;
+                               ret = -ETIMEDOUT;
                        }
                }
 
@@ -418,69 +418,6 @@ static int init_bsp(struct udevice **devp)
        return 0;
 }
 
-#ifdef CONFIG_QFW
-static int qemu_cpu_fixup(void)
-{
-       int ret;
-       int cpu_num;
-       int cpu_online;
-       struct udevice *dev, *pdev;
-       struct cpu_platdata *plat;
-       char *cpu;
-
-       /* first we need to find '/cpus' */
-       for (device_find_first_child(dm_root(), &pdev);
-            pdev;
-            device_find_next_child(&pdev)) {
-               if (!strcmp(pdev->name, "cpus"))
-                       break;
-       }
-       if (!pdev) {
-               printf("unable to find cpus device\n");
-               return -ENODEV;
-       }
-
-       /* calculate cpus that are already bound */
-       cpu_num = 0;
-       for (uclass_find_first_device(UCLASS_CPU, &dev);
-            dev;
-            uclass_find_next_device(&dev)) {
-               cpu_num++;
-       }
-
-       /* get actual cpu number */
-       cpu_online = qemu_fwcfg_online_cpus();
-       if (cpu_online < 0) {
-               printf("unable to get online cpu number: %d\n", cpu_online);
-               return cpu_online;
-       }
-
-       /* bind addtional cpus */
-       dev = NULL;
-       for (; cpu_num < cpu_online; cpu_num++) {
-               /*
-                * allocate device name here as device_bind_driver() does
-                * not copy device name, 8 bytes are enough for
-                * sizeof("cpu@") + 3 digits cpu number + '\0'
-                */
-               cpu = malloc(8);
-               if (!cpu) {
-                       printf("unable to allocate device name\n");
-                       return -ENOMEM;
-               }
-               sprintf(cpu, "cpu@%d", cpu_num);
-               ret = device_bind_driver(pdev, "cpu_qemu", cpu, &dev);
-               if (ret) {
-                       printf("binding cpu@%d failed: %d\n", cpu_num, ret);
-                       return ret;
-               }
-               plat = dev_get_parent_platdata(dev);
-               plat->cpu_id = cpu_num;
-       }
-       return 0;
-}
-#endif
-
 int mp_init(struct mp_params *p)
 {
        int num_aps;
@@ -494,11 +431,11 @@ int mp_init(struct mp_params *p)
        if (ret)
                return ret;
 
-#ifdef CONFIG_QFW
-       ret = qemu_cpu_fixup();
-       if (ret)
-               return ret;
-#endif
+       if (IS_ENABLED(CONFIG_QFW)) {
+               ret = qemu_cpu_fixup();
+               if (ret)
+                       return ret;
+       }
 
        ret = init_bsp(&cpu);
        if (ret) {
@@ -508,7 +445,7 @@ int mp_init(struct mp_params *p)
 
        if (p == NULL || p->flight_plan == NULL || p->num_records < 1) {
                printf("Invalid MP parameters\n");
-               return -1;
+               return -EINVAL;
        }
 
        num_cpus = cpu_get_count(cpu);
@@ -531,7 +468,7 @@ int mp_init(struct mp_params *p)
        /* Load the SIPI vector */
        ret = load_sipi_vector(&ap_count, num_cpus);
        if (ap_count == NULL)
-               return -1;
+               return -ENOENT;
 
        /*
         * Make sure SIPI data hits RAM so the APs that come up will see