Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2018 |
| 4 | * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc |
| 5 | */ |
| 6 | |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <cpu.h> |
| 9 | |
Sean Anderson | 79d3bba | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 10 | static int cpu_sandbox_get_desc(const struct udevice *dev, char *buf, int size) |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 11 | { |
| 12 | snprintf(buf, size, "LEG Inc. SuperMegaUltraTurbo CPU No. 1"); |
| 13 | |
| 14 | return 0; |
| 15 | } |
| 16 | |
Sean Anderson | 79d3bba | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 17 | static int cpu_sandbox_get_info(const struct udevice *dev, |
| 18 | struct cpu_info *info) |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 19 | { |
| 20 | info->cpu_freq = 42 * 42 * 42 * 42 * 42; |
| 21 | info->features = 0x42424242; |
Simon Glass | c35854a | 2020-04-08 16:57:20 -0600 | [diff] [blame] | 22 | info->address_width = IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32; |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 23 | |
| 24 | return 0; |
| 25 | } |
| 26 | |
Sean Anderson | 79d3bba | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 27 | static int cpu_sandbox_get_count(const struct udevice *dev) |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 28 | { |
| 29 | return 42; |
| 30 | } |
| 31 | |
Sean Anderson | 79d3bba | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 32 | static int cpu_sandbox_get_vendor(const struct udevice *dev, char *buf, |
| 33 | int size) |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 34 | { |
| 35 | snprintf(buf, size, "Languid Example Garbage Inc."); |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
Heinrich Schuchardt | 20f9d3d | 2021-08-28 11:42:08 +0200 | [diff] [blame] | 40 | static const char *cpu_current = "cpu@1"; |
Sean Anderson | 79d3bba | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 41 | |
| 42 | void cpu_sandbox_set_current(const char *name) |
Peng Fan | 35c589a | 2020-05-03 21:58:48 +0800 | [diff] [blame] | 43 | { |
Sean Anderson | 79d3bba | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 44 | cpu_current = name; |
| 45 | } |
| 46 | |
Hou Zhiqiang | 4274452 | 2024-08-01 11:59:48 +0800 | [diff] [blame] | 47 | static int cpu_sandbox_release_core(const struct udevice *dev, phys_addr_t addr) |
| 48 | { |
| 49 | return 0; |
| 50 | } |
| 51 | |
Sean Anderson | 79d3bba | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 52 | static int cpu_sandbox_is_current(struct udevice *dev) |
| 53 | { |
| 54 | if (!strcmp(dev->name, cpu_current)) |
Peng Fan | 35c589a | 2020-05-03 21:58:48 +0800 | [diff] [blame] | 55 | return 1; |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 60 | static 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, |
Peng Fan | 35c589a | 2020-05-03 21:58:48 +0800 | [diff] [blame] | 65 | .is_current = cpu_sandbox_is_current, |
Hou Zhiqiang | 4274452 | 2024-08-01 11:59:48 +0800 | [diff] [blame] | 66 | .release_core = cpu_sandbox_release_core, |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 67 | }; |
| 68 | |
Sean Anderson | 79d3bba | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 69 | static int cpu_sandbox_bind(struct udevice *dev) |
| 70 | { |
| 71 | int ret; |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 72 | struct cpu_plat *plat = dev_get_parent_plat(dev); |
Sean Anderson | 79d3bba | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 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 | |
| 84 | static int cpu_sandbox_probe(struct udevice *dev) |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 85 | { |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | static const struct udevice_id cpu_sandbox_ids[] = { |
| 90 | { .compatible = "sandbox,cpu_sandbox" }, |
| 91 | { } |
| 92 | }; |
| 93 | |
| 94 | U_BOOT_DRIVER(cpu_sandbox) = { |
| 95 | .name = "cpu_sandbox", |
| 96 | .id = UCLASS_CPU, |
| 97 | .ops = &cpu_sandbox_ops, |
| 98 | .of_match = cpu_sandbox_ids, |
Sean Anderson | 79d3bba | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 99 | .bind = cpu_sandbox_bind, |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 100 | .probe = cpu_sandbox_probe, |
| 101 | }; |