1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
7 #define LOG_CATEGORY UCLASS_CPU
16 #include <linux/err.h>
19 DECLARE_GLOBAL_DATA_PTR;
21 int cpu_probe_all(void)
23 int ret = uclass_probe_all(UCLASS_CPU);
26 debug("%s: Error while probing CPUs (err = %d %s)\n",
27 __func__, ret, errno_str(ret));
32 int cpu_is_current(struct udevice *cpu)
34 struct cpu_ops *ops = cpu_get_ops(cpu);
36 if (ops->is_current) {
37 if (ops->is_current(cpu))
44 struct udevice *cpu_get_current_dev(void)
49 uclass_foreach_dev_probe(UCLASS_CPU, cpu) {
50 if (cpu_is_current(cpu) > 0)
54 /* If can't find current cpu device, use the first dev instead */
55 ret = uclass_first_device_err(UCLASS_CPU, &cpu);
57 debug("%s: Could not get CPU device (err = %d)\n",
65 int cpu_get_desc(const struct udevice *dev, char *buf, int size)
67 struct cpu_ops *ops = cpu_get_ops(dev);
72 return ops->get_desc(dev, buf, size);
75 int cpu_get_info(const struct udevice *dev, struct cpu_info *info)
77 struct cpu_ops *ops = cpu_get_ops(dev);
82 /* Init cpu_info to 0 */
83 memset(info, 0, sizeof(struct cpu_info));
85 return ops->get_info(dev, info);
88 int cpu_get_count(const struct udevice *dev)
90 struct cpu_ops *ops = cpu_get_ops(dev);
95 return ops->get_count(dev);
98 int cpu_get_vendor(const struct udevice *dev, char *buf, int size)
100 struct cpu_ops *ops = cpu_get_ops(dev);
102 if (!ops->get_vendor)
105 return ops->get_vendor(dev, buf, size);
108 U_BOOT_DRIVER(cpu_bus) = {
110 .id = UCLASS_SIMPLE_BUS,
111 .per_child_plat_auto = sizeof(struct cpu_plat),
114 static int uclass_cpu_init(struct uclass *uc)
120 node = ofnode_path("/cpus");
121 if (!ofnode_valid(node))
124 ret = device_bind_driver_to_node(dm_root(), "cpu_bus", "cpus", node,
130 static int uclass_cpu_post_bind(struct udevice *dev)
132 if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC) &&
133 (gd->flags & GD_FLG_RELOC)) {
134 struct cpu_ops *ops = cpu_get_ops(dev);
135 static int reloc_done;
139 MANUAL_RELOC(ops->get_desc);
141 MANUAL_RELOC(ops->get_info);
143 MANUAL_RELOC(ops->get_count);
145 MANUAL_RELOC(ops->get_vendor);
147 MANUAL_RELOC(ops->is_current);
156 UCLASS_DRIVER(cpu) = {
159 .flags = DM_UC_FLAG_SEQ_ALIAS,
160 .init = uclass_cpu_init,
161 .post_bind = uclass_cpu_post_bind,