]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h
b6e6ae5bc50a2ae1399b3edbd499001c0fc188e8
[mirror_edk2.git] / UefiCpuPkg / Library / CpuCacheInfoLib / InternalCpuCacheInfoLib.h
1 /** @file
2 Internal header file for CPU Cache info Library.
3
4 Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef _INTERNAL_CPU_CACHE_INFO_LIB_H_
10 #define _INTERNAL_CPU_CACHE_INFO_LIB_H_
11
12 #include <PiPei.h>
13 #include <Register/Cpuid.h>
14 #include <Ppi/MpServices2.h>
15 #include <Protocol/MpService.h>
16 #include <Library/BaseLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Library/CpuCacheInfoLib.h>
21
22 typedef struct {
23 //
24 // Package ID, the information comes from
25 // EFI_CPU_PHYSICAL_LOCATION.Package
26 //
27 UINT32 Package;
28 //
29 // APIC ID, the information comes from
30 // EFI_PROCESSOR_INFORMATION.ProcessorId
31 //
32 UINT32 ApicId;
33 //
34 // Core type of logical processor.
35 // Value = CPUID.1Ah:EAX[31:24]
36 //
37 UINT8 CoreType;
38 } CPUID_PROCESSOR_INFO;
39
40 typedef struct {
41 //
42 // Level of the cache.
43 // Value = CPUID.04h:EAX[07:05]
44 //
45 UINT8 CacheLevel : 3;
46 //
47 // Type of the cache.
48 // Value = CPUID.04h:EAX[04:00]
49 //
50 UINT8 CacheType : 5;
51 //
52 // Ways of associativity.
53 // Value = CPUID.04h:EBX[31:22]
54 //
55 UINT16 CacheWays : 10;
56 //
57 // Fully associative cache.
58 // Value = CPUID.04h:EAX[09]
59 //
60 UINT16 FullyAssociativeCache : 1;
61 //
62 // Direct mapped cache.
63 // Value = CPUID.04h:EDX[02]
64 //
65 UINT16 DirectMappedCache : 1;
66 UINT16 Reserved : 4;
67 //
68 // Cache share bits.
69 // Value = CPUID.04h:EAX[25:14]
70 //
71 UINT16 CacheShareBits;
72 //
73 // Size of single cache.
74 // Value = (CPUID.04h:EBX[31:22] + 1) * (CPUID.04h:EBX[21:12] + 1) *
75 // (CPUID.04h:EBX[11:00] + 1) * (CPUID.04h:ECX[31:00] + 1)
76 //
77 UINT32 CacheSizeinKB;
78 } CPUID_CACHE_DATA;
79
80 typedef union {
81 EDKII_PEI_MP_SERVICES2_PPI *Ppi;
82 EFI_MP_SERVICES_PROTOCOL *Protocol;
83 } MP_SERVICES;
84
85 typedef struct {
86 MP_SERVICES MpServices;
87 CPUID_PROCESSOR_INFO *ProcessorInfo;
88 CPUID_CACHE_DATA *CacheData;
89 } COLLECT_CPUID_CACHE_DATA_CONTEXT;
90
91
92 /*
93 Defines the maximum count of Deterministic Cache Parameters Leaf of all APs and BSP.
94 To save boot time, skip starting up all APs to calculate each AP's count of Deterministic
95 Cache Parameters Leaf, so use a definition instead.
96 Anyway, definition value will be checked in CpuCacheInfoCollectCoreAndCacheData function.
97 */
98 #define MAX_NUM_OF_CACHE_PARAMS_LEAF 6
99
100 /*
101 Defines the maximum count of packages.
102 */
103 #define MAX_NUM_OF_PACKAGE 100
104
105 /**
106 Get EDKII_PEI_MP_SERVICES2_PPI or EFI_MP_SERVICES_PROTOCOL pointer.
107
108 @param[out] MpServices A pointer to the buffer where EDKII_PEI_MP_SERVICES2_PPI or
109 EFI_MP_SERVICES_PROTOCOL is stored
110
111 @retval EFI_SUCCESS EDKII_PEI_MP_SERVICES2_PPI or EFI_MP_SERVICES_PROTOCOL interface is returned
112 @retval EFI_NOT_FOUND EDKII_PEI_MP_SERVICES2_PPI or EFI_MP_SERVICES_PROTOCOL interface is not found
113 **/
114 EFI_STATUS
115 CpuCacheInfoGetMpServices (
116 OUT MP_SERVICES *MpServices
117 );
118
119 /**
120 Activate all of the logical processors.
121
122 @param[in] MpServices MP_SERVICES structure.
123 @param[in] Procedure A pointer to the function to be run on enabled logical processors.
124 @param[in] ProcedureArgument The parameter passed into Procedure for all enabled logical processors.
125 **/
126 VOID
127 CpuCacheInfoStartupAllCPUs (
128 IN MP_SERVICES MpServices,
129 IN EFI_AP_PROCEDURE Procedure,
130 IN VOID *ProcedureArgument
131 );
132
133 /**
134 Get detailed information of the requested logical processor.
135
136 @param[in] MpServices MP_SERVICES structure.
137 @param[in] ProcessorNum The requested logical processor number.
138 @param[out] ProcessorInfo A pointer to the buffer where the processor information is stored
139 **/
140 VOID
141 CpuCacheInfoGetProcessorInfo (
142 IN MP_SERVICES MpServices,
143 IN UINTN ProcessorNum,
144 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo
145 );
146
147 /**
148 Get the logical processor number.
149
150 @param[in] MpServices MP_SERVICES structure.
151
152 @retval Return the logical processor number.
153 **/
154 UINT32
155 CpuCacheInfoWhoAmI (
156 IN MP_SERVICES MpServices
157 );
158
159 /**
160 Get the total number of logical processors in the platform.
161
162 @param[in] MpServices MP_SERVICES structure.
163
164 @retval Return the total number of logical processors.
165 **/
166 UINT32
167 CpuCacheInfoGetNumberOfProcessors (
168 IN MP_SERVICES MpServices
169 );
170 #endif