1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
11 #include <dm/uclass-internal.h>
14 int qemu_cpu_fixup(void)
19 struct udevice *dev, *pdev;
20 struct cpu_platdata *plat;
23 /* first we need to find '/cpus' */
24 for (device_find_first_child(dm_root(), &pdev);
26 device_find_next_child(&pdev)) {
27 if (!strcmp(pdev->name, "cpus"))
31 printf("unable to find cpus device\n");
35 /* calculate cpus that are already bound */
37 for (uclass_find_first_device(UCLASS_CPU, &dev);
39 uclass_find_next_device(&dev)) {
43 /* get actual cpu number */
44 cpu_online = qemu_fwcfg_online_cpus();
46 printf("unable to get online cpu number: %d\n", cpu_online);
50 /* bind addtional cpus */
52 for (; cpu_num < cpu_online; cpu_num++) {
54 * allocate device name here as device_bind_driver() does
55 * not copy device name, 8 bytes are enough for
56 * sizeof("cpu@") + 3 digits cpu number + '\0'
60 printf("unable to allocate device name\n");
63 sprintf(cpu, "cpu@%d", cpu_num);
64 ret = device_bind_driver(pdev, "cpu_qemu", cpu, &dev);
66 printf("binding cpu@%d failed: %d\n", cpu_num, ret);
69 plat = dev_get_parent_platdata(dev);
70 plat->cpu_id = cpu_num;