1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
12 #include <dm/uclass-internal.h>
15 int qemu_cpu_fixup(void)
20 struct udevice *dev, *pdev;
21 struct cpu_platdata *plat;
24 /* first we need to find '/cpus' */
25 for (device_find_first_child(dm_root(), &pdev);
27 device_find_next_child(&pdev)) {
28 if (!strcmp(pdev->name, "cpus"))
32 printf("unable to find cpus device\n");
36 /* calculate cpus that are already bound */
38 for (uclass_find_first_device(UCLASS_CPU, &dev);
40 uclass_find_next_device(&dev)) {
44 /* get actual cpu number */
45 cpu_online = qemu_fwcfg_online_cpus();
47 printf("unable to get online cpu number: %d\n", cpu_online);
51 /* bind addtional cpus */
53 for (; cpu_num < cpu_online; cpu_num++) {
55 * allocate device name here as device_bind_driver() does
56 * not copy device name, 8 bytes are enough for
57 * sizeof("cpu@") + 3 digits cpu number + '\0'
61 printf("unable to allocate device name\n");
64 sprintf(cpu, "cpu@%d", cpu_num);
65 ret = device_bind_driver(pdev, "cpu_qemu", cpu, &dev);
67 printf("binding cpu@%d failed: %d\n", cpu_num, ret);
70 plat = dev_get_parent_platdata(dev);
71 plat->cpu_id = cpu_num;