]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
11f4dc15 SG |
2 | /* |
3 | * Copyright (c) 2015 Google, Inc | |
4 | * Written by Simon Glass <[email protected]> | |
11f4dc15 SG |
5 | */ |
6 | ||
7 | #ifndef __CPU_H | |
8 | #define __CPU_H | |
9 | ||
401d1c4f SG |
10 | struct udevice; |
11 | ||
11f4dc15 | 12 | /** |
8a8d24bd | 13 | * struct cpu_plat - platform data for a CPU |
50d188b9 MS |
14 | * @cpu_id: Platform-specific way of identifying the CPU. |
15 | * @ucode_version: Microcode version, if CPU_FEAT_UCODE is set | |
16 | * @device_id: Driver-defined device identifier | |
17 | * @family: DMTF CPU Family identifier | |
18 | * @id: DMTF CPU Processor identifier | |
b8596947 BM |
19 | * @timebase_freq: the current frequency at which the cpu timer timebase |
20 | * registers are updated (in Hz) | |
11f4dc15 | 21 | * |
caa4daa2 | 22 | * This can be accessed with dev_get_parent_plat() for any UCLASS_CPU |
11f4dc15 | 23 | * device. |
11f4dc15 | 24 | */ |
8a8d24bd | 25 | struct cpu_plat { |
11f4dc15 | 26 | int cpu_id; |
740d5d34 SG |
27 | int ucode_version; |
28 | ulong device_id; | |
50d188b9 MS |
29 | u16 family; |
30 | u32 id[2]; | |
b8596947 | 31 | u32 timebase_freq; |
11f4dc15 SG |
32 | }; |
33 | ||
34 | /* CPU features - mostly just a placeholder for now */ | |
35 | enum { | |
36 | CPU_FEAT_L1_CACHE = 0, /* Supports level 1 cache */ | |
37 | CPU_FEAT_MMU = 1, /* Supports virtual memory */ | |
740d5d34 SG |
38 | CPU_FEAT_UCODE = 2, /* Requires/uses microcode */ |
39 | CPU_FEAT_DEVICE_ID = 3, /* Provides a device ID */ | |
11f4dc15 SG |
40 | |
41 | CPU_FEAT_COUNT, | |
42 | }; | |
43 | ||
44 | /** | |
45 | * struct cpu_info - Information about a CPU | |
46 | * | |
47 | * @cpu_freq: Current CPU frequency in Hz | |
48 | * @features: Flags for supported CPU features | |
600f584d | 49 | * @address_width: Width of the CPU address space in bits (e.g. 32) |
11f4dc15 SG |
50 | */ |
51 | struct cpu_info { | |
52 | ulong cpu_freq; | |
53 | ulong features; | |
600f584d | 54 | uint address_width; |
11f4dc15 SG |
55 | }; |
56 | ||
57 | struct cpu_ops { | |
58 | /** | |
59 | * get_desc() - Get a description string for a CPU | |
60 | * | |
61 | * @dev: Device to check (UCLASS_CPU) | |
62 | * @buf: Buffer to place string | |
63 | * @size: Size of string space | |
64 | * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error | |
65 | */ | |
961420fa | 66 | int (*get_desc)(const struct udevice *dev, char *buf, int size); |
11f4dc15 SG |
67 | |
68 | /** | |
69 | * get_info() - Get information about a CPU | |
70 | * | |
71 | * @dev: Device to check (UCLASS_CPU) | |
72 | * @info: Returns CPU info | |
73 | * @return 0 if OK, -ve on error | |
74 | */ | |
961420fa | 75 | int (*get_info)(const struct udevice *dev, struct cpu_info *info); |
780bfdd3 BM |
76 | |
77 | /** | |
78 | * get_count() - Get number of CPUs | |
79 | * | |
80 | * @dev: Device to check (UCLASS_CPU) | |
81 | * @return CPU count if OK, -ve on error | |
82 | */ | |
961420fa | 83 | int (*get_count)(const struct udevice *dev); |
94eaa79c AG |
84 | |
85 | /** | |
86 | * get_vendor() - Get vendor name of a CPU | |
87 | * | |
88 | * @dev: Device to check (UCLASS_CPU) | |
89 | * @buf: Buffer to place string | |
90 | * @size: Size of string space | |
91 | * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error | |
92 | */ | |
961420fa | 93 | int (*get_vendor)(const struct udevice *dev, char *buf, int size); |
4c809aee PF |
94 | |
95 | /** | |
96 | * is_current() - Check if the CPU that U-Boot is currently running from | |
97 | * | |
98 | * @dev: Device to check (UCLASS_CPU) | |
99 | * @return 1 if the CPU that U-Boot is currently running from, 0 | |
100 | * if not. | |
101 | */ | |
102 | int (*is_current)(struct udevice *dev); | |
11f4dc15 SG |
103 | }; |
104 | ||
105 | #define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops) | |
106 | ||
107 | /** | |
108 | * cpu_get_desc() - Get a description string for a CPU | |
11f4dc15 SG |
109 | * @dev: Device to check (UCLASS_CPU) |
110 | * @buf: Buffer to place string | |
111 | * @size: Size of string space | |
50d188b9 MS |
112 | * |
113 | * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error | |
11f4dc15 | 114 | */ |
961420fa | 115 | int cpu_get_desc(const struct udevice *dev, char *buf, int size); |
11f4dc15 SG |
116 | |
117 | /** | |
118 | * cpu_get_info() - Get information about a CPU | |
11f4dc15 SG |
119 | * @dev: Device to check (UCLASS_CPU) |
120 | * @info: Returns CPU info | |
50d188b9 MS |
121 | * |
122 | * Return: 0 if OK, -ve on error | |
11f4dc15 | 123 | */ |
961420fa | 124 | int cpu_get_info(const struct udevice *dev, struct cpu_info *info); |
11f4dc15 | 125 | |
780bfdd3 BM |
126 | /** |
127 | * cpu_get_count() - Get number of CPUs | |
780bfdd3 | 128 | * @dev: Device to check (UCLASS_CPU) |
50d188b9 MS |
129 | * |
130 | * Return: CPU count if OK, -ve on error | |
780bfdd3 | 131 | */ |
961420fa | 132 | int cpu_get_count(const struct udevice *dev); |
780bfdd3 | 133 | |
94eaa79c AG |
134 | /** |
135 | * cpu_get_vendor() - Get vendor name of a CPU | |
94eaa79c AG |
136 | * @dev: Device to check (UCLASS_CPU) |
137 | * @buf: Buffer to place string | |
138 | * @size: Size of string space | |
50d188b9 MS |
139 | * |
140 | * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error | |
94eaa79c | 141 | */ |
961420fa | 142 | int cpu_get_vendor(const struct udevice *dev, char *buf, int size); |
94eaa79c | 143 | |
57370de3 MS |
144 | /** |
145 | * cpu_probe_all() - Probe all available CPUs | |
146 | * | |
147 | * Return: 0 if OK, -ve on error | |
148 | */ | |
149 | int cpu_probe_all(void); | |
150 | ||
4c809aee PF |
151 | /** |
152 | * cpu_is_current() - Check if the CPU that U-Boot is currently running from | |
153 | * | |
154 | * Return: 1 if yes, - 0 if not | |
155 | */ | |
156 | int cpu_is_current(struct udevice *cpu); | |
157 | ||
158 | /** | |
159 | * cpu_get_current_dev() - Get CPU udevice for current CPU | |
160 | * | |
161 | * Return: udevice if OK, - NULL on error | |
162 | */ | |
163 | struct udevice *cpu_get_current_dev(void); | |
164 | ||
11f4dc15 | 165 | #endif |