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)
20 struct udevice *dev, *pdev, *qfwdev;
21 struct cpu_plat *plat;
24 /* This will cause the CPUs devices to be bound */
25 ret = uclass_get(UCLASS_CPU, &uc);
29 /* first we need to find '/cpus' */
30 for (device_find_first_child(dm_root(), &pdev);
32 device_find_next_child(&pdev)) {
33 if (!strcmp(pdev->name, "cpus"))
37 printf("unable to find cpus device\n");
42 ret = qfw_get_dev(&qfwdev);
44 printf("unable to find qfw device\n");
48 /* calculate cpus that are already bound */
50 for (uclass_find_first_device(UCLASS_CPU, &dev);
52 uclass_find_next_device(&dev)) {
56 /* get actual cpu number */
57 cpu_online = qfw_online_cpus(qfwdev);
59 printf("unable to get online cpu number: %d\n", cpu_online);
63 /* bind addtional cpus */
65 for (; cpu_num < cpu_online; cpu_num++) {
67 * allocate device name here as device_bind_driver() does
68 * not copy device name, 8 bytes are enough for
69 * sizeof("cpu@") + 3 digits cpu number + '\0'
73 printf("unable to allocate device name\n");
76 sprintf(cpu, "cpu@%d", cpu_num);
77 ret = device_bind_driver(pdev, "cpu_qemu", cpu, &dev);
79 printf("binding cpu@%d failed: %d\n", cpu_num, ret);
82 plat = dev_get_parent_plat(dev);
83 plat->cpu_id = cpu_num;