]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Universal/Smbios/ProcessorSubClassDxe/SmbiosProcessorArmCommon.c
ArmPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmPkg / Universal / Smbios / ProcessorSubClassDxe / SmbiosProcessorArmCommon.c
CommitLineData
2ba6ecef
RC
1/** @file\r
2 Functions for processor information common to ARM and AARCH64.\r
3\r
4 Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>\r
ac6388ad 5 Copyright (c) 2021, Ampere Computing LLC. All rights reserved.<BR>\r
2ba6ecef
RC
6\r
7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8\r
9**/\r
10\r
11#include <Uefi.h>\r
a63914d3 12#include <IndustryStandard/ArmCache.h>\r
2ba6ecef
RC
13#include <IndustryStandard/ArmStdSmc.h>\r
14#include <IndustryStandard/SmBios.h>\r
15#include <Library/ArmLib.h>\r
2ba6ecef
RC
16#include <Library/ArmSmcLib.h>\r
17#include <Library/BaseMemoryLib.h>\r
18\r
19#include "SmbiosProcessor.h"\r
20\r
21/** Returns the maximum cache level implemented by the current CPU.\r
22\r
23 @return The maximum cache level implemented.\r
24**/\r
25UINT8\r
26SmbiosProcessorGetMaxCacheLevel (\r
27 VOID\r
28 )\r
29{\r
429309e0
MK
30 CLIDR_DATA Clidr;\r
31 UINT8 CacheLevel;\r
32 UINT8 MaxCacheLevel;\r
2ba6ecef
RC
33\r
34 MaxCacheLevel = 0;\r
35\r
36 // Read the CLIDR register to find out what caches are present.\r
37 Clidr.Data = ReadCLIDR ();\r
38\r
39 // Get the cache type for the L1 cache. If it's 0, there are no caches.\r
40 if (CLIDR_GET_CACHE_TYPE (Clidr.Data, 1) == ClidrCacheTypeNone) {\r
41 return 0;\r
42 }\r
43\r
44 for (CacheLevel = 1; CacheLevel <= MAX_ARM_CACHE_LEVEL; CacheLevel++) {\r
45 if (CLIDR_GET_CACHE_TYPE (Clidr.Data, CacheLevel) == ClidrCacheTypeNone) {\r
46 MaxCacheLevel = CacheLevel;\r
47 break;\r
48 }\r
49 }\r
50\r
51 return MaxCacheLevel;\r
52}\r
53\r
54/** Returns whether or not the specified cache level has separate I/D caches.\r
55\r
56 @param CacheLevel The cache level (L1, L2 etc.).\r
57\r
58 @return TRUE if the cache level has separate I/D caches, FALSE otherwise.\r
59**/\r
60BOOLEAN\r
61SmbiosProcessorHasSeparateCaches (\r
429309e0 62 UINT8 CacheLevel\r
2ba6ecef
RC
63 )\r
64{\r
429309e0
MK
65 CLIDR_CACHE_TYPE CacheType;\r
66 CLIDR_DATA Clidr;\r
67 BOOLEAN SeparateCaches;\r
2ba6ecef
RC
68\r
69 SeparateCaches = FALSE;\r
70\r
71 Clidr.Data = ReadCLIDR ();\r
72\r
73 CacheType = CLIDR_GET_CACHE_TYPE (Clidr.Data, CacheLevel - 1);\r
74\r
75 if (CacheType == ClidrCacheTypeSeparate) {\r
76 SeparateCaches = TRUE;\r
77 }\r
78\r
79 return SeparateCaches;\r
80}\r
81\r
82/** Checks if ther ARM64 SoC ID SMC call is supported\r
83\r
84 @return Whether the ARM64 SoC ID call is supported.\r
85**/\r
86BOOLEAN\r
87HasSmcArm64SocId (\r
88 VOID\r
89 )\r
90{\r
429309e0
MK
91 ARM_SMC_ARGS Args;\r
92 INT32 SmcCallStatus;\r
93 BOOLEAN Arm64SocIdSupported;\r
2ba6ecef
RC
94\r
95 Arm64SocIdSupported = FALSE;\r
96\r
97 Args.Arg0 = SMCCC_VERSION;\r
98 ArmCallSmc (&Args);\r
99 SmcCallStatus = (INT32)Args.Arg0;\r
100\r
429309e0 101 if ((SmcCallStatus < 0) || ((SmcCallStatus >> 16) >= 1)) {\r
2ba6ecef
RC
102 Args.Arg0 = SMCCC_ARCH_FEATURES;\r
103 Args.Arg1 = SMCCC_ARCH_SOC_ID;\r
104 ArmCallSmc (&Args);\r
105\r
106 if (Args.Arg0 >= 0) {\r
107 Arm64SocIdSupported = TRUE;\r
108 }\r
109 }\r
110\r
111 return Arm64SocIdSupported;\r
112}\r
113\r
114/** Fetches the JEP106 code and SoC Revision.\r
115\r
116 @param Jep106Code JEP 106 code.\r
117 @param SocRevision SoC revision.\r
118\r
119 @retval EFI_SUCCESS Succeeded.\r
120 @retval EFI_UNSUPPORTED Failed.\r
121**/\r
122EFI_STATUS\r
123SmbiosGetSmcArm64SocId (\r
429309e0
MK
124 OUT INT32 *Jep106Code,\r
125 OUT INT32 *SocRevision\r
2ba6ecef
RC
126 )\r
127{\r
128 ARM_SMC_ARGS Args;\r
129 INT32 SmcCallStatus;\r
130 EFI_STATUS Status;\r
131\r
132 Status = EFI_SUCCESS;\r
133\r
134 Args.Arg0 = SMCCC_ARCH_SOC_ID;\r
135 Args.Arg1 = 0;\r
136 ArmCallSmc (&Args);\r
137 SmcCallStatus = (INT32)Args.Arg0;\r
138\r
139 if (SmcCallStatus >= 0) {\r
140 *Jep106Code = (INT32)Args.Arg0;\r
141 } else {\r
142 Status = EFI_UNSUPPORTED;\r
143 }\r
144\r
145 Args.Arg0 = SMCCC_ARCH_SOC_ID;\r
146 Args.Arg1 = 1;\r
147 ArmCallSmc (&Args);\r
148 SmcCallStatus = (INT32)Args.Arg0;\r
149\r
150 if (SmcCallStatus >= 0) {\r
151 *SocRevision = (INT32)Args.Arg0;\r
152 } else {\r
153 Status = EFI_UNSUPPORTED;\r
154 }\r
155\r
156 return Status;\r
157}\r
158\r
159/** Returns a value for the Processor ID field that conforms to SMBIOS\r
160 requirements.\r
161\r
162 @return Processor ID.\r
163**/\r
164UINT64\r
165SmbiosGetProcessorId (\r
166 VOID\r
167 )\r
168{\r
429309e0
MK
169 INT32 Jep106Code;\r
170 INT32 SocRevision;\r
171 UINT64 ProcessorId;\r
2ba6ecef
RC
172\r
173 if (HasSmcArm64SocId ()) {\r
174 SmbiosGetSmcArm64SocId (&Jep106Code, &SocRevision);\r
ac6388ad 175 ProcessorId = ((UINT64)SocRevision << 32) | Jep106Code;\r
2ba6ecef
RC
176 } else {\r
177 ProcessorId = ArmReadMidr ();\r
178 }\r
179\r
180 return ProcessorId;\r
181}\r
182\r
183/** Returns the external clock frequency.\r
184\r
185 @return The external clock frequency.\r
186**/\r
187UINTN\r
188SmbiosGetExternalClockFrequency (\r
189 VOID\r
190 )\r
191{\r
192 return ArmReadCntFrq ();\r
193}\r
194\r
195/** Returns the SMBIOS ProcessorFamily field value.\r
196\r
197 @return The value for the ProcessorFamily field.\r
198**/\r
199UINT8\r
200SmbiosGetProcessorFamily (\r
201 VOID\r
202 )\r
203{\r
204 return ProcessorFamilyIndicatorFamily2;\r
205}\r
206\r
207/** Returns the ProcessorFamily2 field value.\r
208\r
209 @return The value for the ProcessorFamily2 field.\r
210**/\r
211UINT16\r
212SmbiosGetProcessorFamily2 (\r
213 VOID\r
214 )\r
215{\r
429309e0
MK
216 UINTN MainIdRegister;\r
217 UINT16 ProcessorFamily2;\r
2ba6ecef
RC
218\r
219 MainIdRegister = ArmReadMidr ();\r
220\r
221 if (((MainIdRegister >> 16) & 0xF) < 8) {\r
222 ProcessorFamily2 = ProcessorFamilyARM;\r
223 } else {\r
429309e0 224 if (sizeof (VOID *) == 4) {\r
2ba6ecef
RC
225 ProcessorFamily2 = ProcessorFamilyARMv7;\r
226 } else {\r
227 ProcessorFamily2 = ProcessorFamilyARMv8;\r
228 }\r
229 }\r
230\r
231 return ProcessorFamily2;\r
232}\r
233\r
234/** Returns the SMBIOS Processor Characteristics.\r
235\r
236 @return Processor Characteristics bitfield.\r
237**/\r
238PROCESSOR_CHARACTERISTIC_FLAGS\r
239SmbiosGetProcessorCharacteristics (\r
240 VOID\r
241 )\r
242{\r
429309e0 243 PROCESSOR_CHARACTERISTIC_FLAGS Characteristics;\r
2ba6ecef
RC
244\r
245 ZeroMem (&Characteristics, sizeof (Characteristics));\r
246\r
247 Characteristics.ProcessorArm64SocId = HasSmcArm64SocId ();\r
248\r
249 return Characteristics;\r
250}\r