Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __CPU_H |
| 8 | #define __CPU_H |
| 9 | |
Tom Rini | 1aad5b5 | 2023-10-12 19:03:54 -0400 | [diff] [blame] | 10 | #include <linux/types.h> |
| 11 | |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | struct udevice; |
| 13 | |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 14 | /** |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 15 | * struct cpu_plat - platform data for a CPU |
Mario Six | 60ce6dd | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 16 | * @cpu_id: Platform-specific way of identifying the CPU. |
| 17 | * @ucode_version: Microcode version, if CPU_FEAT_UCODE is set |
| 18 | * @device_id: Driver-defined device identifier |
| 19 | * @family: DMTF CPU Family identifier |
| 20 | * @id: DMTF CPU Processor identifier |
Bin Meng | b2aa495 | 2018-12-12 06:12:24 -0800 | [diff] [blame] | 21 | * @timebase_freq: the current frequency at which the cpu timer timebase |
| 22 | * registers are updated (in Hz) |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 23 | * |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 24 | * This can be accessed with dev_get_parent_plat() for any UCLASS_CPU |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 25 | * device. |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 26 | */ |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 27 | struct cpu_plat { |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 28 | int cpu_id; |
Simon Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 29 | int ucode_version; |
| 30 | ulong device_id; |
Mario Six | 60ce6dd | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 31 | u16 family; |
| 32 | u32 id[2]; |
Bin Meng | b2aa495 | 2018-12-12 06:12:24 -0800 | [diff] [blame] | 33 | u32 timebase_freq; |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | /* CPU features - mostly just a placeholder for now */ |
| 37 | enum { |
| 38 | CPU_FEAT_L1_CACHE = 0, /* Supports level 1 cache */ |
| 39 | CPU_FEAT_MMU = 1, /* Supports virtual memory */ |
Simon Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 40 | CPU_FEAT_UCODE = 2, /* Requires/uses microcode */ |
| 41 | CPU_FEAT_DEVICE_ID = 3, /* Provides a device ID */ |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 42 | |
| 43 | CPU_FEAT_COUNT, |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * struct cpu_info - Information about a CPU |
| 48 | * |
| 49 | * @cpu_freq: Current CPU frequency in Hz |
| 50 | * @features: Flags for supported CPU features |
Simon Glass | c35854a | 2020-04-08 16:57:20 -0600 | [diff] [blame] | 51 | * @address_width: Width of the CPU address space in bits (e.g. 32) |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 52 | */ |
| 53 | struct cpu_info { |
| 54 | ulong cpu_freq; |
| 55 | ulong features; |
Simon Glass | c35854a | 2020-04-08 16:57:20 -0600 | [diff] [blame] | 56 | uint address_width; |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | struct cpu_ops { |
| 60 | /** |
| 61 | * get_desc() - Get a description string for a CPU |
| 62 | * |
| 63 | * @dev: Device to check (UCLASS_CPU) |
| 64 | * @buf: Buffer to place string |
| 65 | * @size: Size of string space |
| 66 | * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
| 67 | */ |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 68 | int (*get_desc)(const struct udevice *dev, char *buf, int size); |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * get_info() - Get information about a CPU |
| 72 | * |
| 73 | * @dev: Device to check (UCLASS_CPU) |
| 74 | * @info: Returns CPU info |
| 75 | * @return 0 if OK, -ve on error |
| 76 | */ |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 77 | int (*get_info)(const struct udevice *dev, struct cpu_info *info); |
Bin Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * get_count() - Get number of CPUs |
| 81 | * |
| 82 | * @dev: Device to check (UCLASS_CPU) |
| 83 | * @return CPU count if OK, -ve on error |
| 84 | */ |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 85 | int (*get_count)(const struct udevice *dev); |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * get_vendor() - Get vendor name of a CPU |
| 89 | * |
| 90 | * @dev: Device to check (UCLASS_CPU) |
| 91 | * @buf: Buffer to place string |
| 92 | * @size: Size of string space |
| 93 | * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
| 94 | */ |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 95 | int (*get_vendor)(const struct udevice *dev, char *buf, int size); |
Peng Fan | 221763a | 2020-05-03 21:58:47 +0800 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * is_current() - Check if the CPU that U-Boot is currently running from |
| 99 | * |
| 100 | * @dev: Device to check (UCLASS_CPU) |
| 101 | * @return 1 if the CPU that U-Boot is currently running from, 0 |
| 102 | * if not. |
| 103 | */ |
| 104 | int (*is_current)(struct udevice *dev); |
Hou Zhiqiang | ace391d | 2024-08-01 11:59:47 +0800 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * release_core() - Relase a CPU core to the given address to run application |
| 108 | * |
| 109 | * @dev: Device to check (UCLASS_CPU) |
| 110 | * @addr: Address to relese the CPU core |
| 111 | * @return 0 if OK, -ve on error |
| 112 | */ |
| 113 | int (*release_core)(const struct udevice *dev, phys_addr_t addr); |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | #define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops) |
| 117 | |
| 118 | /** |
| 119 | * cpu_get_desc() - Get a description string for a CPU |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 120 | * @dev: Device to check (UCLASS_CPU) |
| 121 | * @buf: Buffer to place string |
| 122 | * @size: Size of string space |
Mario Six | 60ce6dd | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 123 | * |
| 124 | * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 125 | */ |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 126 | int cpu_get_desc(const struct udevice *dev, char *buf, int size); |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * cpu_get_info() - Get information about a CPU |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 130 | * @dev: Device to check (UCLASS_CPU) |
| 131 | * @info: Returns CPU info |
Mario Six | 60ce6dd | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 132 | * |
| 133 | * Return: 0 if OK, -ve on error |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 134 | */ |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 135 | int cpu_get_info(const struct udevice *dev, struct cpu_info *info); |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 136 | |
Bin Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 137 | /** |
| 138 | * cpu_get_count() - Get number of CPUs |
Bin Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 139 | * @dev: Device to check (UCLASS_CPU) |
Mario Six | 60ce6dd | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 140 | * |
| 141 | * Return: CPU count if OK, -ve on error |
Bin Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 142 | */ |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 143 | int cpu_get_count(const struct udevice *dev); |
Bin Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 144 | |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 145 | /** |
| 146 | * cpu_get_vendor() - Get vendor name of a CPU |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 147 | * @dev: Device to check (UCLASS_CPU) |
| 148 | * @buf: Buffer to place string |
| 149 | * @size: Size of string space |
Mario Six | 60ce6dd | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 150 | * |
| 151 | * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 152 | */ |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 153 | int cpu_get_vendor(const struct udevice *dev, char *buf, int size); |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 154 | |
Mario Six | 0263b43 | 2018-08-06 10:23:43 +0200 | [diff] [blame] | 155 | /** |
| 156 | * cpu_probe_all() - Probe all available CPUs |
| 157 | * |
| 158 | * Return: 0 if OK, -ve on error |
| 159 | */ |
| 160 | int cpu_probe_all(void); |
| 161 | |
Peng Fan | 221763a | 2020-05-03 21:58:47 +0800 | [diff] [blame] | 162 | /** |
| 163 | * cpu_is_current() - Check if the CPU that U-Boot is currently running from |
| 164 | * |
| 165 | * Return: 1 if yes, - 0 if not |
| 166 | */ |
| 167 | int cpu_is_current(struct udevice *cpu); |
| 168 | |
| 169 | /** |
| 170 | * cpu_get_current_dev() - Get CPU udevice for current CPU |
| 171 | * |
| 172 | * Return: udevice if OK, - NULL on error |
| 173 | */ |
| 174 | struct udevice *cpu_get_current_dev(void); |
| 175 | |
Hou Zhiqiang | ace391d | 2024-08-01 11:59:47 +0800 | [diff] [blame] | 176 | /** |
| 177 | * cpu_release_core() - Relase a CPU core to the given address to run application |
| 178 | * |
| 179 | * @return 0 if OK, -ve on error |
| 180 | */ |
| 181 | int cpu_release_core(const struct udevice *dev, phys_addr_t addr); |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 182 | #endif |