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)
21 struct udevice *dev, *pdev, *qfwdev;
22 struct cpu_plat *plat;
25 /* This will cause the CPUs devices to be bound */
26 ret = uclass_get(UCLASS_CPU, &uc);
30 /* first we need to find '/cpus' */
31 for (device_find_first_child(dm_root(), &pdev);
33 device_find_next_child(&pdev)) {
34 if (!strcmp(pdev->name, "cpus"))
38 printf("unable to find cpus device\n");
43 ret = qfw_get_dev(&qfwdev);
45 printf("unable to find qfw device\n");
49 /* calculate cpus that are already bound */
51 for (uclass_find_first_device(UCLASS_CPU, &dev);
53 uclass_find_next_device(&dev)) {
57 /* get actual cpu number */
58 cpu_online = qfw_online_cpus(qfwdev);
60 printf("unable to get online cpu number: %d\n", cpu_online);
64 /* bind addtional cpus */
66 for (; cpu_num < cpu_online; cpu_num++) {
68 * allocate device name here as device_bind_driver() does
69 * not copy device name, 8 bytes are enough for
70 * sizeof("cpu@") + 3 digits cpu number + '\0'
74 printf("unable to allocate device name\n");
77 sprintf(cpu, "cpu@%d", cpu_num);
78 ret = device_bind_driver(pdev, "cpu_qemu", cpu, &dev);
80 printf("binding cpu@%d failed: %d\n", cpu_num, ret);
83 plat = dev_get_parent_plat(dev);
84 plat->cpu_id = cpu_num;