TianoCore EDK2 master
Loading...
Searching...
No Matches
PrmSampleHardwareAccessModule.c File Reference
#include <PrmModule.h>
#include <Library/BaseLib.h>
#include <Library/MtrrLib.h>
#include <Library/UefiLib.h>
#include <Register/Intel/ArchitecturalMsr.h>
#include <Register/Intel/Cpuid.h>
#include "Hpet.h"

Go to the source code of this file.

Macros

#define MSR_ACCESS_MICROCODE_SIGNATURE_PRM_HANDLER_GUID   {0x2120cd3c, 0x848b, 0x4d8f, {0xab, 0xbb, 0x4b, 0x74, 0xce, 0x64, 0xac, 0x89}}
 
#define MSR_ACCESS_MTRR_DUMP_PRM_HANDLER_GUID   {0xea0935a7, 0x506b, 0x4159, {0xbb, 0xbb, 0x48, 0xde, 0xee, 0xcb, 0x6f, 0x58}}
 
#define MMIO_ACCESS_HPET_PRM_HANDLER_GUID   {0x1bd1bda9, 0x909a, 0x4614, {0x96, 0x99, 0x25, 0xec, 0x0c, 0x27, 0x83, 0xf7}}
 

Functions

VOID MtrrLibInitializeMtrrMask (OUT UINT64 *MtrrValidBitsMask, OUT UINT64 *MtrrValidAddressMask)
 
UINT32 MtrrLibGetRawVariableRanges (IN MTRR_VARIABLE_SETTINGS *VariableSettings, IN UINTN VariableMtrrCount, IN UINT64 MtrrValidBitsMask, IN UINT64 MtrrValidAddressMask, OUT MTRR_MEMORY_RANGE *VariableMtrr)
 
RETURN_STATUS MtrrLibApplyFixedMtrrs (IN MTRR_FIXED_SETTINGS *Fixed, IN OUT MTRR_MEMORY_RANGE *Ranges, IN UINTN RangeCapacity, IN OUT UINTN *RangeCount)
 
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)
 
VOID EFIAPI AccessAllMtrrs (VOID)
 
UINT64 EFIAPI HpetRead (IN UINTN Offset)
 
VOID EFIAPI AccessHpetConfiguration (VOID)
 
UINT32 GetMicrocodeSignature (VOID)
 
 PRM_HANDLER_EXPORT (MsrAccessMicrocodeSignaturePrmHandler)
 
 PRM_HANDLER_EXPORT (MsrAccessMtrrDumpPrmHandler)
 
 PRM_HANDLER_EXPORT (MmioAccessHpetPrmHandler)
 
 PRM_MODULE_EXPORT (PRM_HANDLER_EXPORT_ENTRY(MSR_ACCESS_MICROCODE_SIGNATURE_PRM_HANDLER_GUID, MsrAccessMicrocodeSignaturePrmHandler), PRM_HANDLER_EXPORT_ENTRY(MSR_ACCESS_MTRR_DUMP_PRM_HANDLER_GUID, MsrAccessMtrrDumpPrmHandler),)
 
EFI_STATUS EFIAPI PrmSampleHardwareAccessModuleInit (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 

Variables

CONST CHAR8 * mMtrrMemoryCacheTypeShortName []
 

Detailed Description

A sample PRM Module implementation. This PRM Module provides PRM handlers that perform various types of hardware access. This is simply meant to demonstrate hardware access capabilities from a PRM handler.

Copyright (c) Microsoft Corporation SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file PrmSampleHardwareAccessModule.c.

Macro Definition Documentation

◆ MMIO_ACCESS_HPET_PRM_HANDLER_GUID

#define MMIO_ACCESS_HPET_PRM_HANDLER_GUID   {0x1bd1bda9, 0x909a, 0x4614, {0x96, 0x99, 0x25, 0xec, 0x0c, 0x27, 0x83, 0xf7}}

Definition at line 33 of file PrmSampleHardwareAccessModule.c.

◆ MSR_ACCESS_MICROCODE_SIGNATURE_PRM_HANDLER_GUID

#define MSR_ACCESS_MICROCODE_SIGNATURE_PRM_HANDLER_GUID   {0x2120cd3c, 0x848b, 0x4d8f, {0xab, 0xbb, 0x4b, 0x74, 0xce, 0x64, 0xac, 0x89}}

Definition at line 27 of file PrmSampleHardwareAccessModule.c.

◆ MSR_ACCESS_MTRR_DUMP_PRM_HANDLER_GUID

#define MSR_ACCESS_MTRR_DUMP_PRM_HANDLER_GUID   {0xea0935a7, 0x506b, 0x4159, {0xbb, 0xbb, 0x48, 0xde, 0xee, 0xcb, 0x6f, 0x58}}

Definition at line 30 of file PrmSampleHardwareAccessModule.c.

Function Documentation

◆ AccessAllMtrrs()

VOID EFIAPI AccessAllMtrrs ( VOID  )

Accesses MTRR values including architectural and variable MTRRs.

Definition at line 129 of file PrmSampleHardwareAccessModule.c.

◆ AccessHpetConfiguration()

VOID EFIAPI AccessHpetConfiguration ( VOID  )

Accesses HPET configuration information.

Definition at line 221 of file PrmSampleHardwareAccessModule.c.

◆ GetMicrocodeSignature()

UINT32 GetMicrocodeSignature ( VOID  )

Reads the microcode signature from architectural MSR 0x8B.

Return values
MicrocodeSignatureThe microcode signature value.

Definition at line 235 of file PrmSampleHardwareAccessModule.c.

◆ HpetRead()

UINT64 EFIAPI HpetRead ( IN UINTN  Offset)

Reads a HPET MMIO register.

Reads the 64-bit HPET MMIO register specified by Address.

This function must guarantee that all MMIO read and write operations are serialized.

If Address is not aligned on a 64-bit boundary, zero will be returned.

Parameters
OffsetSpecifies the offset of the HPET register to read.
Returns
The value read.

Definition at line 195 of file PrmSampleHardwareAccessModule.c.

◆ MtrrLibApplyFixedMtrrs()

RETURN_STATUS MtrrLibApplyFixedMtrrs ( IN MTRR_FIXED_SETTINGS Fixed,
IN OUT MTRR_MEMORY_RANGE Ranges,
IN UINTN  RangeCapacity,
IN OUT UINTN RangeCount 
)

Apply the fixed MTRR settings to memory range array.

Parameters
FixedThe fixed MTRR settings.
RangesReturn the memory range array holding memory type settings for all memory address.
RangeCapacityThe capacity of memory range array.
RangeCountReturn the count of memory range.
Return values
RETURN_SUCCESSThe memory range array is returned successfully.
RETURN_OUT_OF_RESOURCESThe count of memory ranges exceeds capacity.

◆ MtrrLibApplyVariableMtrrs()

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 
)

Apply the variable MTRR settings to memory range array.

Parameters
VariableMtrrThe variable MTRR array.
VariableMtrrCountThe count of variable MTRRs.
RangesReturn the memory range array with new MTRR settings applied.
RangeCapacityThe capacity of memory range array.
RangeCountReturn the count of memory range.
Return values
RETURN_SUCCESSThe memory range array is returned successfully.
RETURN_OUT_OF_RESOURCESThe count of memory ranges exceeds capacity.

Definition at line 1884 of file MtrrLib.c.

◆ MtrrLibGetRawVariableRanges()

UINT32 MtrrLibGetRawVariableRanges ( IN MTRR_VARIABLE_SETTINGS VariableSettings,
IN UINTN  VariableMtrrCount,
IN UINT64  MtrrValidBitsMask,
IN UINT64  MtrrValidAddressMask,
OUT MTRR_MEMORY_RANGE VariableMtrr 
)

Convert variable MTRRs to a RAW MTRR_MEMORY_RANGE array. One MTRR_MEMORY_RANGE element is created for each MTRR setting. The routine doesn't remove the overlap or combine the near-by region.

Parameters
[in]VariableSettingsThe variable MTRR values to shadow
[in]VariableMtrrCountThe number of variable MTRRs
[in]MtrrValidBitsMaskThe mask for the valid bit of the MTRR
[in]MtrrValidAddressMaskThe valid address mask for MTRR
[out]VariableMtrrThe array to shadow variable MTRRs content
Returns
Number of MTRRs which has been used.

◆ MtrrLibInitializeMtrrMask()

VOID MtrrLibInitializeMtrrMask ( OUT UINT64 *  MtrrValidBitsMask,
OUT UINT64 *  MtrrValidAddressMask 
)

Initializes the valid bits mask and valid address mask for MTRRs.

This function initializes the valid bits mask and valid address mask for MTRRs.

Parameters
[out]MtrrValidBitsMaskThe mask for the valid bit of the MTRR
[out]MtrrValidAddressMaskThe valid address mask for the MTRR

Definition at line 823 of file MtrrLib.c.

◆ PRM_HANDLER_EXPORT() [1/3]

PRM_HANDLER_EXPORT ( MmioAccessHpetPrmHandler  )

A sample Platform Runtime Mechanism (PRM) handler.

This sample handler attempts to read from a HPET MMIO resource.

Parameters
[in]ParameterBufferA pointer to the PRM handler parameter buffer
[in]ContextBUfferA pointer to the PRM handler context buffer
Return values
EFI_STATUSThe PRM handler executed successfully.
OthersAn error occurred in the PRM handler.

Definition at line 303 of file PrmSampleHardwareAccessModule.c.

◆ PRM_HANDLER_EXPORT() [2/3]

PRM_HANDLER_EXPORT ( MsrAccessMicrocodeSignaturePrmHandler  )

A sample Platform Runtime Mechanism (PRM) handler.

This sample handler attempts to read the microcode update signature.

Parameters
[in]ParameterBufferA pointer to the PRM handler parameter buffer
[in]ContextBUfferA pointer to the PRM handler context buffer
Return values
EFI_STATUSThe PRM handler executed successfully.
OthersAn error occurred in the PRM handler.

Definition at line 260 of file PrmSampleHardwareAccessModule.c.

◆ PRM_HANDLER_EXPORT() [3/3]

PRM_HANDLER_EXPORT ( MsrAccessMtrrDumpPrmHandler  )

A sample Platform Runtime Mechanism (PRM) handler.

This sample handler attempts to read the current MTRR settings.

Parameters
[in]ParameterBufferA pointer to the PRM handler parameter buffer
[in]ContextBUfferA pointer to the PRM handler context buffer
Return values
EFI_STATUSThe PRM handler executed successfully.
OthersAn error occurred in the PRM handler.

Definition at line 285 of file PrmSampleHardwareAccessModule.c.

◆ PrmSampleHardwareAccessModuleInit()

EFI_STATUS EFIAPI PrmSampleHardwareAccessModuleInit ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

Module entry point.

Parameters
[in]ImageHandleThe image handle.
[in]SystemTableA pointer to the system table.
Return values
EFI_SUCCESSThis function always returns success.

Definition at line 329 of file PrmSampleHardwareAccessModule.c.

Variable Documentation

◆ mMtrrMemoryCacheTypeShortName

CONST CHAR8* mMtrrMemoryCacheTypeShortName[]
extern

Definition at line 119 of file MtrrLib.c.