]> Git Repo - u-boot.git/blob - arch/x86/cpu/qfw_cpu.c
Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"
[u-boot.git] / arch / x86 / cpu / qfw_cpu.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2015 Google, Inc
4  */
5
6 #include <cpu.h>
7 #include <dm.h>
8 #include <malloc.h>
9 #include <qfw.h>
10 #include <dm/lists.h>
11 #include <dm/uclass-internal.h>
12 #include <dm/root.h>
13
14 int qemu_cpu_fixup(void)
15 {
16         int ret;
17         int cpu_num;
18         int cpu_online;
19         struct uclass *uc;
20         struct udevice *dev, *pdev, *qfwdev;
21         struct cpu_plat *plat;
22         char *cpu;
23
24         /* This will cause the CPUs devices to be bound */
25         ret = uclass_get(UCLASS_CPU, &uc);
26         if (ret)
27                 return ret;
28
29         /* first we need to find '/cpus' */
30         for (device_find_first_child(dm_root(), &pdev);
31              pdev;
32              device_find_next_child(&pdev)) {
33                 if (!strcmp(pdev->name, "cpus"))
34                         break;
35         }
36         if (!pdev) {
37                 printf("unable to find cpus device\n");
38                 return -ENODEV;
39         }
40
41         /* get qfw dev */
42         ret = qfw_get_dev(&qfwdev);
43         if (ret) {
44                 printf("unable to find qfw device\n");
45                 return ret;
46         }
47
48         /* calculate cpus that are already bound */
49         cpu_num = 0;
50         for (uclass_find_first_device(UCLASS_CPU, &dev);
51              dev;
52              uclass_find_next_device(&dev)) {
53                 cpu_num++;
54         }
55
56         /* get actual cpu number */
57         cpu_online = qfw_online_cpus(qfwdev);
58         if (cpu_online < 0) {
59                 printf("unable to get online cpu number: %d\n", cpu_online);
60                 return cpu_online;
61         }
62
63         /* bind addtional cpus */
64         dev = NULL;
65         for (; cpu_num < cpu_online; cpu_num++) {
66                 /*
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'
70                  */
71                 cpu = malloc(8);
72                 if (!cpu) {
73                         printf("unable to allocate device name\n");
74                         return -ENOMEM;
75                 }
76                 sprintf(cpu, "cpu@%d", cpu_num);
77                 ret = device_bind_driver(pdev, "cpu_qemu", cpu, &dev);
78                 if (ret) {
79                         printf("binding cpu@%d failed: %d\n", cpu_num, ret);
80                         return ret;
81                 }
82                 plat = dev_get_parent_plat(dev);
83                 plat->cpu_id = cpu_num;
84         }
85         return 0;
86 }
This page took 0.031063 seconds and 4 git commands to generate.