"Das U-Boot" Source Tree
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2018
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5 */
6
7#include <dm.h>
8#include <cpu.h>
9
10static int cpu_sandbox_get_desc(const struct udevice *dev, char *buf, int size)
11{
12 snprintf(buf, size, "LEG Inc. SuperMegaUltraTurbo CPU No. 1");
13
14 return 0;
15}
16
17static int cpu_sandbox_get_info(const struct udevice *dev,
18 struct cpu_info *info)
19{
20 info->cpu_freq = 42 * 42 * 42 * 42 * 42;
21 info->features = 0x42424242;
22 info->address_width = IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32;
23
24 return 0;
25}
26
27static int cpu_sandbox_get_count(const struct udevice *dev)
28{
29 return 42;
30}
31
32static int cpu_sandbox_get_vendor(const struct udevice *dev, char *buf,
33 int size)
34{
35 snprintf(buf, size, "Languid Example Garbage Inc.");
36
37 return 0;
38}
39
40static const char *cpu_current = "cpu@1";
41
42void cpu_sandbox_set_current(const char *name)
43{
44 cpu_current = name;
45}
46
47static int cpu_sandbox_release_core(const struct udevice *dev, phys_addr_t addr)
48{
49 return 0;
50}
51
52static int cpu_sandbox_is_current(struct udevice *dev)
53{
54 if (!strcmp(dev->name, cpu_current))
55 return 1;
56
57 return 0;
58}
59
60static const struct cpu_ops cpu_sandbox_ops = {
61 .get_desc = cpu_sandbox_get_desc,
62 .get_info = cpu_sandbox_get_info,
63 .get_count = cpu_sandbox_get_count,
64 .get_vendor = cpu_sandbox_get_vendor,
65 .is_current = cpu_sandbox_is_current,
66 .release_core = cpu_sandbox_release_core,
67};
68
69static int cpu_sandbox_bind(struct udevice *dev)
70{
71 int ret;
72 struct cpu_plat *plat = dev_get_parent_plat(dev);
73
74 /* first examine the property in current cpu node */
75 ret = dev_read_u32(dev, "timebase-frequency", &plat->timebase_freq);
76 /* if not found, then look at the parent /cpus node */
77 if (ret)
78 ret = dev_read_u32(dev->parent, "timebase-frequency",
79 &plat->timebase_freq);
80
81 return ret;
82}
83
84static int cpu_sandbox_probe(struct udevice *dev)
85{
86 return 0;
87}
88
89static const struct udevice_id cpu_sandbox_ids[] = {
90 { .compatible = "sandbox,cpu_sandbox" },
91 { }
92};
93
94U_BOOT_DRIVER(cpu_sandbox) = {
95 .name = "cpu_sandbox",
96 .id = UCLASS_CPU,
97 .ops = &cpu_sandbox_ops,
98 .of_match = cpu_sandbox_ids,
99 .bind = cpu_sandbox_bind,
100 .probe = cpu_sandbox_probe,
101};