]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
x86: Move qemu CPU fixup function into its own file
authorSimon Glass <sjg@chromium.org>
Sat, 7 Dec 2019 04:42:55 +0000 (21:42 -0700)
committerBin Meng <bmeng.cn@gmail.com>
Sun, 15 Dec 2019 03:44:25 +0000 (11:44 +0800)
This function is specific to qemu so it seems best to keep it separate
from the generic code.

Move it out to a new file and update the condition to use if() instead of
 #ifdef

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
arch/x86/cpu/Makefile
arch/x86/cpu/mp_init.c
arch/x86/cpu/qfw_cpu.c [new file with mode: 0644]
include/qfw.h

index b6a010ea320aa50ad925874305b55ee9f703d05a..0e90a38dc5efbd27c9fcf27a7472e75bdc152163 100644 (file)
@@ -54,6 +54,7 @@ obj-$(CONFIG_INTEL_QUEENSBAY) += queensbay/
 obj-$(CONFIG_INTEL_TANGIER) += tangier/
 obj-$(CONFIG_APIC) += lapic.o ioapic.o
 obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += irq.o
+obj-$(CONFIG_QFW) += qfw_cpu.o
 ifndef CONFIG_$(SPL_)X86_64
 obj-$(CONFIG_SMP) += mp_init.o
 endif
index fefbf8f72829b5e9a65dc8de363990bec3c007fd..7b09f90cd518e449cd59635bdc996429cf1b0700 100644 (file)
@@ -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) {
diff --git a/arch/x86/cpu/qfw_cpu.c b/arch/x86/cpu/qfw_cpu.c
new file mode 100644 (file)
index 0000000..49e9dfc
--- /dev/null
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2015 Google, Inc
+ */
+
+#include <common.h>
+#include <cpu.h>
+#include <dm.h>
+#include <qfw.h>
+#include <dm/lists.h>
+#include <dm/uclass-internal.h>
+#include <dm/root.h>
+
+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;
+}
index 2f1a20416f83e7c7e40b82bcb0bea0a76555b94a..cea8e11d4431eb664609632f56554762dbcfb19c 100644 (file)
@@ -172,4 +172,12 @@ bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter *iter);
 bool qemu_fwcfg_present(void);
 bool qemu_fwcfg_dma_present(void);
 
+/**
+ * qemu_cpu_fixup() - Fix up the CPUs for QEMU
+ *
+ * @return 0 if OK, -ENODEV if no CPUs, -ENOMEM if out of memory, other -ve on
+ *     on other error
+ */
+int qemu_cpu_fixup(void);
+
 #endif