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