TianoCore EDK2 master
Loading...
Searching...
No Matches
PrmSampleHardwareAccessModule.c
Go to the documentation of this file.
1
11#include <PrmModule.h>
12
13#include <Library/BaseLib.h>
14#include <Library/MtrrLib.h>
15#include <Library/UefiLib.h>
16
19
20#include "Hpet.h"
21
22//
23// PRM Handler GUIDs
24//
25
26// {2120cd3c-848b-4d8f-abbb-4b74ce64ac89}
27#define MSR_ACCESS_MICROCODE_SIGNATURE_PRM_HANDLER_GUID {0x2120cd3c, 0x848b, 0x4d8f, {0xab, 0xbb, 0x4b, 0x74, 0xce, 0x64, 0xac, 0x89}}
28
29// {ea0935a7-506b-4159-bbbb-48deeecb6f58}
30#define MSR_ACCESS_MTRR_DUMP_PRM_HANDLER_GUID {0xea0935a7, 0x506b, 0x4159, {0xbb, 0xbb, 0x48, 0xde, 0xee, 0xcb, 0x6f, 0x58}}
31
32// {1bd1bda9-909a-4614-9699-25ec0c2783f7}
33#define MMIO_ACCESS_HPET_PRM_HANDLER_GUID {0x1bd1bda9, 0x909a, 0x4614, {0x96, 0x99, 0x25, 0xec, 0x0c, 0x27, 0x83, 0xf7}}
34
35//
36// BEGIN: MtrrLib internal library globals and function prototypes here for testing
37//
38extern CONST CHAR8 *mMtrrMemoryCacheTypeShortName[];
39
49VOID
51 OUT UINT64 *MtrrValidBitsMask,
52 OUT UINT64 *MtrrValidAddressMask
53 );
54
69UINT32
71 IN MTRR_VARIABLE_SETTINGS *VariableSettings,
72 IN UINTN VariableMtrrCount,
73 IN UINT64 MtrrValidBitsMask,
74 IN UINT64 MtrrValidAddressMask,
75 OUT MTRR_MEMORY_RANGE *VariableMtrr
76 );
77
90RETURN_STATUS
93 IN OUT MTRR_MEMORY_RANGE *Ranges,
94 IN UINTN RangeCapacity,
95 IN OUT UINTN *RangeCount
96 );
97
110RETURN_STATUS
112 IN CONST MTRR_MEMORY_RANGE *VariableMtrr,
113 IN UINT32 VariableMtrrCount,
114 IN OUT MTRR_MEMORY_RANGE *Ranges,
115 IN UINTN RangeCapacity,
116 IN OUT UINTN *RangeCount
117 );
118
119//
120// END: MtrrLib internal library function prototypes here for testing
121//
122
127VOID
128EFIAPI
130 VOID
131 )
132{
133 MTRR_SETTINGS LocalMtrrs;
134 MTRR_SETTINGS *Mtrrs;
135 UINTN RangeCount;
136 UINT64 MtrrValidBitsMask;
137 UINT64 MtrrValidAddressMask;
138 UINT32 VariableMtrrCount;
139
140 MTRR_MEMORY_RANGE Ranges[
141 MTRR_NUMBER_OF_FIXED_MTRR * sizeof (UINT64) + 2 * ARRAY_SIZE (Mtrrs->Variables.Mtrr) + 1
142 ];
143 MTRR_MEMORY_RANGE RawVariableRanges[ARRAY_SIZE (Mtrrs->Variables.Mtrr)];
144
145 if (!IsMtrrSupported ()) {
146 return;
147 }
148
149 VariableMtrrCount = GetVariableMtrrCount ();
150
151 MtrrGetAllMtrrs (&LocalMtrrs);
152 Mtrrs = &LocalMtrrs;
153
154 MtrrLibInitializeMtrrMask (&MtrrValidBitsMask, &MtrrValidAddressMask);
155 Ranges[0].BaseAddress = 0;
156 Ranges[0].Length = MtrrValidBitsMask + 1;
157 Ranges[0].Type = MtrrGetDefaultMemoryType ();
158 RangeCount = 1;
159
161 &Mtrrs->Variables,
162 VariableMtrrCount,
163 MtrrValidBitsMask,
164 MtrrValidAddressMask,
165 RawVariableRanges
166 );
168 RawVariableRanges,
169 VariableMtrrCount,
170 Ranges,
171 ARRAY_SIZE (Ranges),
172 &RangeCount
173 );
174
175 MtrrLibApplyFixedMtrrs (&Mtrrs->Fixed, Ranges, ARRAY_SIZE (Ranges), &RangeCount);
176}
177
193UINT64
194EFIAPI
196 IN UINTN Offset
197 )
198{
199 UINTN Address;
200 UINT64 Value;
201
202 Address = HPET_BASE_ADDRESS + Offset;
203
204 if ((Address & 7) == 0) {
205 return 0;
206 }
207
208 MemoryFence ();
209 Value = *(volatile UINT64 *)Address;
210 MemoryFence ();
211
212 return Value;
213}
214
219VOID
220EFIAPI
222 VOID
223 )
224{
226 HpetRead (HPET_GENERAL_CONFIGURATION_OFFSET);
227}
228
234UINT32
236 VOID
237 )
238{
239 MSR_IA32_BIOS_SIGN_ID_REGISTER BiosSignIdMsr;
240
243 BiosSignIdMsr.Uint64 = AsmReadMsr64 (MSR_IA32_BIOS_SIGN_ID);
244
245 return BiosSignIdMsr.Bits.MicrocodeUpdateSignature;
246}
247
260PRM_HANDLER_EXPORT (MsrAccessMicrocodeSignaturePrmHandler) {
261 UINT32 MicrocodeSignature;
262
263 MicrocodeSignature = 0;
264 MicrocodeSignature = GetMicrocodeSignature ();
265
266 if (MicrocodeSignature == 0) {
267 return EFI_NOT_FOUND;
268 }
269
270 return EFI_SUCCESS;
271}
272
285PRM_HANDLER_EXPORT (MsrAccessMtrrDumpPrmHandler) {
287
288 return EFI_SUCCESS;
289}
290
303PRM_HANDLER_EXPORT (MmioAccessHpetPrmHandler) {
305
306 return EFI_SUCCESS;
307}
308
309//
310// Register the PRM export information for this PRM Module
311//
313 PRM_HANDLER_EXPORT_ENTRY (MSR_ACCESS_MICROCODE_SIGNATURE_PRM_HANDLER_GUID, MsrAccessMicrocodeSignaturePrmHandler),
314 PRM_HANDLER_EXPORT_ENTRY (MSR_ACCESS_MTRR_DUMP_PRM_HANDLER_GUID, MsrAccessMtrrDumpPrmHandler),
315 PRM_HANDLER_EXPORT_ENTRY (MMIO_ACCESS_HPET_PRM_HANDLER_GUID, MmioAccessHpetPrmHandler)
316 );
317
328EFIAPI
330 IN EFI_HANDLE ImageHandle,
331 IN EFI_SYSTEM_TABLE *SystemTable
332 )
333{
334 return EFI_SUCCESS;
335}
UINT64 UINTN
VOID EFIAPI MemoryFence(VOID)
Definition: CpuBreakpoint.c:42
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
Definition: GccInlinePriv.c:60
UINT64 EFIAPI AsmWriteMsr64(IN UINT32 Index, IN UINT64 Value)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define MSR_IA32_BIOS_SIGN_ID
#define CPUID_VERSION_INFO
Definition: Cpuid.h:81
UINT32 EFIAPI AsmCpuid(IN UINT32 Index, OUT UINT32 *RegisterEax OPTIONAL, OUT UINT32 *RegisterEbx OPTIONAL, OUT UINT32 *RegisterEcx OPTIONAL, OUT UINT32 *RegisterEdx OPTIONAL)
Definition: CpuId.c:36
UINT32 EFIAPI GetVariableMtrrCount(VOID)
Definition: MtrrLib.c:235
BOOLEAN EFIAPI IsMtrrSupported(VOID)
Definition: MtrrLib.c:2960
MTRR_MEMORY_CACHE_TYPE EFIAPI MtrrGetDefaultMemoryType(VOID)
Definition: MtrrLib.c:324
MTRR_SETTINGS *EFIAPI MtrrGetAllMtrrs(OUT MTRR_SETTINGS *MtrrSetting)
Definition: MtrrLib.c:2851
#define HPET_GENERAL_CAPABILITIES_ID_OFFSET
Definition: Hpet.h:16
#define PRM_MODULE_EXPORT(...)
#define PRM_HANDLER_EXPORT_ENTRY(Guid, Name)
#define PRM_HANDLER_EXPORT(Name)
Definition: PrmModule.h:26
RETURN_STATUS MtrrLibApplyFixedMtrrs(IN MTRR_FIXED_SETTINGS *Fixed, IN OUT MTRR_MEMORY_RANGE *Ranges, IN UINTN RangeCapacity, IN OUT UINTN *RangeCount)
VOID MtrrLibInitializeMtrrMask(OUT UINT64 *MtrrValidBitsMask, OUT UINT64 *MtrrValidAddressMask)
Definition: MtrrLib.c:823
RETURN_STATUS MtrrLibApplyVariableMtrrs(IN CONST MTRR_MEMORY_RANGE *VariableMtrr, IN UINT32 VariableMtrrCount, IN OUT MTRR_MEMORY_RANGE *Ranges, IN UINTN RangeCapacity, IN OUT UINTN *RangeCount)
Definition: MtrrLib.c:1884
VOID EFIAPI AccessHpetConfiguration(VOID)
UINT32 MtrrLibGetRawVariableRanges(IN MTRR_VARIABLE_SETTINGS *VariableSettings, IN UINTN VariableMtrrCount, IN UINT64 MtrrValidBitsMask, IN UINT64 MtrrValidAddressMask, OUT MTRR_MEMORY_RANGE *VariableMtrr)
UINT64 EFIAPI HpetRead(IN UINTN Offset)
EFI_STATUS EFIAPI PrmSampleHardwareAccessModuleInit(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID EFIAPI AccessAllMtrrs(VOID)
UINT32 GetMicrocodeSignature(VOID)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
struct MSR_IA32_BIOS_SIGN_ID_REGISTER::@629 Bits