1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
14 #include <linux/err.h>
16 int cpu_probe_all(void)
21 ret = uclass_first_device(UCLASS_CPU, &cpu);
23 debug("%s: No CPU found (err = %d)\n", __func__, ret);
28 ret = uclass_next_device(&cpu);
30 debug("%s: Error while probing CPU (err = %d)\n",
39 int cpu_is_current(struct udevice *cpu)
41 struct cpu_ops *ops = cpu_get_ops(cpu);
43 if (ops->is_current) {
44 if (ops->is_current(cpu))
51 struct udevice *cpu_get_current_dev(void)
56 uclass_foreach_dev_probe(UCLASS_CPU, cpu) {
57 if (cpu_is_current(cpu) > 0)
61 /* If can't find current cpu device, use the first dev instead */
62 ret = uclass_first_device_err(UCLASS_CPU, &cpu);
64 debug("%s: Could not get CPU device (err = %d)\n",
72 int cpu_get_desc(struct udevice *dev, char *buf, int size)
74 struct cpu_ops *ops = cpu_get_ops(dev);
79 return ops->get_desc(dev, buf, size);
82 int cpu_get_info(struct udevice *dev, struct cpu_info *info)
84 struct cpu_ops *ops = cpu_get_ops(dev);
89 /* Init cpu_info to 0 */
90 memset(info, 0, sizeof(struct cpu_info));
92 return ops->get_info(dev, info);
95 int cpu_get_count(struct udevice *dev)
97 struct cpu_ops *ops = cpu_get_ops(dev);
102 return ops->get_count(dev);
105 int cpu_get_vendor(struct udevice *dev, char *buf, int size)
107 struct cpu_ops *ops = cpu_get_ops(dev);
109 if (!ops->get_vendor)
112 return ops->get_vendor(dev, buf, size);
115 U_BOOT_DRIVER(cpu_bus) = {
117 .id = UCLASS_SIMPLE_BUS,
118 .per_child_platdata_auto_alloc_size = sizeof(struct cpu_platdata),
121 static int uclass_cpu_init(struct uclass *uc)
127 node = ofnode_path("/cpus");
128 if (!ofnode_valid(node))
131 ret = device_bind_driver_to_node(dm_root(), "cpu_bus", "cpus", node,
137 UCLASS_DRIVER(cpu) = {
140 .flags = DM_UC_FLAG_SEQ_ALIAS,
141 .init = uclass_cpu_init,