1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
7 #define LOG_CATEGORY UCLASS_CPU
15 #include <linux/err.h>
18 DECLARE_GLOBAL_DATA_PTR;
20 int cpu_probe_all(void)
22 int ret = uclass_probe_all(UCLASS_CPU);
25 debug("%s: Error while probing CPUs (err = %d %s)\n",
26 __func__, ret, errno_str(ret));
31 int cpu_is_current(struct udevice *cpu)
33 struct cpu_ops *ops = cpu_get_ops(cpu);
35 if (ops->is_current) {
36 if (ops->is_current(cpu))
43 struct udevice *cpu_get_current_dev(void)
48 uclass_foreach_dev_probe(UCLASS_CPU, cpu) {
49 if (cpu_is_current(cpu) > 0)
53 /* If can't find current cpu device, use the first dev instead */
54 ret = uclass_first_device_err(UCLASS_CPU, &cpu);
56 debug("%s: Could not get CPU device (err = %d)\n",
64 int cpu_get_desc(const struct udevice *dev, char *buf, int size)
66 struct cpu_ops *ops = cpu_get_ops(dev);
71 return ops->get_desc(dev, buf, size);
74 int cpu_get_info(const struct udevice *dev, struct cpu_info *info)
76 struct cpu_ops *ops = cpu_get_ops(dev);
81 /* Init cpu_info to 0 */
82 memset(info, 0, sizeof(struct cpu_info));
84 return ops->get_info(dev, info);
87 int cpu_get_count(const struct udevice *dev)
89 struct cpu_ops *ops = cpu_get_ops(dev);
94 return ops->get_count(dev);
97 int cpu_get_vendor(const struct udevice *dev, char *buf, int size)
99 struct cpu_ops *ops = cpu_get_ops(dev);
101 if (!ops->get_vendor)
104 return ops->get_vendor(dev, buf, size);
107 U_BOOT_DRIVER(cpu_bus) = {
109 .id = UCLASS_SIMPLE_BUS,
110 .per_child_plat_auto = sizeof(struct cpu_plat),
113 static int uclass_cpu_init(struct uclass *uc)
119 node = ofnode_path("/cpus");
120 if (!ofnode_valid(node))
123 ret = device_bind_driver_to_node(dm_root(), "cpu_bus", "cpus", node,
129 UCLASS_DRIVER(cpu) = {
132 .flags = DM_UC_FLAG_SEQ_ALIAS,
133 .init = uclass_cpu_init,