2 Functions for processor information common to ARM and AARCH64.
4 Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
5 Copyright (c) 2021, Ampere Computing LLC. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <IndustryStandard/ArmCache.h>
13 #include <IndustryStandard/ArmStdSmc.h>
14 #include <IndustryStandard/SmBios.h>
15 #include <Library/ArmLib.h>
16 #include <Library/ArmSmcLib.h>
17 #include <Library/BaseMemoryLib.h>
19 #include "SmbiosProcessor.h"
21 /** Returns the maximum cache level implemented by the current CPU.
23 @return The maximum cache level implemented.
26 SmbiosProcessorGetMaxCacheLevel (
36 // Read the CLIDR register to find out what caches are present.
37 Clidr
.Data
= ReadCLIDR ();
39 // Get the cache type for the L1 cache. If it's 0, there are no caches.
40 if (CLIDR_GET_CACHE_TYPE (Clidr
.Data
, 1) == ClidrCacheTypeNone
) {
44 for (CacheLevel
= 1; CacheLevel
<= MAX_ARM_CACHE_LEVEL
; CacheLevel
++) {
45 if (CLIDR_GET_CACHE_TYPE (Clidr
.Data
, CacheLevel
) == ClidrCacheTypeNone
) {
46 MaxCacheLevel
= CacheLevel
;
54 /** Returns whether or not the specified cache level has separate I/D caches.
56 @param CacheLevel The cache level (L1, L2 etc.).
58 @return TRUE if the cache level has separate I/D caches, FALSE otherwise.
61 SmbiosProcessorHasSeparateCaches (
65 CLIDR_CACHE_TYPE CacheType
;
67 BOOLEAN SeparateCaches
;
69 SeparateCaches
= FALSE
;
71 Clidr
.Data
= ReadCLIDR ();
73 CacheType
= CLIDR_GET_CACHE_TYPE (Clidr
.Data
, CacheLevel
- 1);
75 if (CacheType
== ClidrCacheTypeSeparate
) {
76 SeparateCaches
= TRUE
;
79 return SeparateCaches
;
82 /** Checks if ther ARM64 SoC ID SMC call is supported
84 @return Whether the ARM64 SoC ID call is supported.
93 BOOLEAN Arm64SocIdSupported
;
95 Arm64SocIdSupported
= FALSE
;
97 Args
.Arg0
= SMCCC_VERSION
;
99 SmcCallStatus
= (INT32
)Args
.Arg0
;
101 if (SmcCallStatus
< 0 || (SmcCallStatus
>> 16) >= 1) {
102 Args
.Arg0
= SMCCC_ARCH_FEATURES
;
103 Args
.Arg1
= SMCCC_ARCH_SOC_ID
;
106 if (Args
.Arg0
>= 0) {
107 Arm64SocIdSupported
= TRUE
;
111 return Arm64SocIdSupported
;
114 /** Fetches the JEP106 code and SoC Revision.
116 @param Jep106Code JEP 106 code.
117 @param SocRevision SoC revision.
119 @retval EFI_SUCCESS Succeeded.
120 @retval EFI_UNSUPPORTED Failed.
123 SmbiosGetSmcArm64SocId (
124 OUT INT32
*Jep106Code
,
125 OUT INT32
*SocRevision
132 Status
= EFI_SUCCESS
;
134 Args
.Arg0
= SMCCC_ARCH_SOC_ID
;
137 SmcCallStatus
= (INT32
)Args
.Arg0
;
139 if (SmcCallStatus
>= 0) {
140 *Jep106Code
= (INT32
)Args
.Arg0
;
142 Status
= EFI_UNSUPPORTED
;
145 Args
.Arg0
= SMCCC_ARCH_SOC_ID
;
148 SmcCallStatus
= (INT32
)Args
.Arg0
;
150 if (SmcCallStatus
>= 0) {
151 *SocRevision
= (INT32
)Args
.Arg0
;
153 Status
= EFI_UNSUPPORTED
;
159 /** Returns a value for the Processor ID field that conforms to SMBIOS
162 @return Processor ID.
165 SmbiosGetProcessorId (
173 if (HasSmcArm64SocId ()) {
174 SmbiosGetSmcArm64SocId (&Jep106Code
, &SocRevision
);
175 ProcessorId
= ((UINT64
)SocRevision
<< 32) | Jep106Code
;
177 ProcessorId
= ArmReadMidr ();
183 /** Returns the external clock frequency.
185 @return The external clock frequency.
188 SmbiosGetExternalClockFrequency (
192 return ArmReadCntFrq ();
195 /** Returns the SMBIOS ProcessorFamily field value.
197 @return The value for the ProcessorFamily field.
200 SmbiosGetProcessorFamily (
204 return ProcessorFamilyIndicatorFamily2
;
207 /** Returns the ProcessorFamily2 field value.
209 @return The value for the ProcessorFamily2 field.
212 SmbiosGetProcessorFamily2 (
216 UINTN MainIdRegister
;
217 UINT16 ProcessorFamily2
;
219 MainIdRegister
= ArmReadMidr ();
221 if (((MainIdRegister
>> 16) & 0xF) < 8) {
222 ProcessorFamily2
= ProcessorFamilyARM
;
224 if (sizeof (VOID
*) == 4) {
225 ProcessorFamily2
= ProcessorFamilyARMv7
;
227 ProcessorFamily2
= ProcessorFamilyARMv8
;
231 return ProcessorFamily2
;
234 /** Returns the SMBIOS Processor Characteristics.
236 @return Processor Characteristics bitfield.
238 PROCESSOR_CHARACTERISTIC_FLAGS
239 SmbiosGetProcessorCharacteristics (
243 PROCESSOR_CHARACTERISTIC_FLAGS Characteristics
;
245 ZeroMem (&Characteristics
, sizeof (Characteristics
));
247 Characteristics
.ProcessorArm64SocId
= HasSmcArm64SocId ();
249 return Characteristics
;