\r
#include <Library/BaseLib.h>\r
#include <Library/MtrrLib.h>\r
-#include <Library/PrintLib.h>\r
#include <Library/UefiLib.h>\r
\r
#include <Register/Intel/ArchitecturalMsr.h>\r
// {2120cd3c-848b-4d8f-abbb-4b74ce64ac89}\r
#define MSR_ACCESS_MICROCODE_SIGNATURE_PRM_HANDLER_GUID {0x2120cd3c, 0x848b, 0x4d8f, {0xab, 0xbb, 0x4b, 0x74, 0xce, 0x64, 0xac, 0x89}}\r
\r
-// {5d28b4e7-3867-4aee-aa09-51fc282c3b22}\r
-#define MSR_PRINT_MICROCODE_SIGNATURE_PRM_HANDLER_GUID {0x5d28b4e7, 0x3867, 0x4aee, {0xaa, 0x09, 0x51, 0xfc, 0x28, 0x2c, 0x3b, 0x22}}\r
-\r
// {ea0935a7-506b-4159-bbbb-48deeecb6f58}\r
#define MSR_ACCESS_MTRR_DUMP_PRM_HANDLER_GUID {0xea0935a7, 0x506b, 0x4159, {0xbb, 0xbb, 0x48, 0xde, 0xee, 0xcb, 0x6f, 0x58}}\r
\r
-// {4b64b702-4d2b-4dfe-ac5a-0b4110a2ca47}\r
-#define MSR_PRINT_MTRR_DUMP_PRM_HANDLER_GUID {0x4b64b702, 0x4d2b, 0x4dfe, {0xac, 0x5a, 0x0b, 0x41, 0x10, 0xa2, 0xca, 0x47}}\r
-\r
// {1bd1bda9-909a-4614-9699-25ec0c2783f7}\r
#define MMIO_ACCESS_HPET_PRM_HANDLER_GUID {0x1bd1bda9, 0x909a, 0x4614, {0x96, 0x99, 0x25, 0xec, 0x0c, 0x27, 0x83, 0xf7}}\r
\r
-// {8a0efdde-78d0-45f0-aea0-c28245c7e1db}\r
-#define MMIO_PRINT_HPET_PRM_HANDLER_GUID {0x8a0efdde, 0x78d0, 0x45f0, {0xae, 0xa0, 0xc2, 0x82, 0x45, 0xc7, 0xe1, 0xdb}}\r
-\r
//\r
// BEGIN: MtrrLib internal library globals and function prototypes here for testing\r
//\r
/**\r
Accesses MTRR values including architectural and variable MTRRs.\r
\r
- If the optional OsServiceDebugPrint function pointer is provided that function is\r
- used to print the MTRR settings.\r
-\r
- @param[in] OsServiceDebugPrint A pointer to an OS-provided debug print function.\r
-\r
**/\r
VOID\r
EFIAPI\r
AccessAllMtrrs (\r
- IN PRM_OS_SERVICE_DEBUG_PRINT OsServiceDebugPrint OPTIONAL\r
+ VOID\r
)\r
{\r
MTRR_SETTINGS LocalMtrrs;\r
MTRR_SETTINGS *Mtrrs;\r
- UINTN Index;\r
UINTN RangeCount;\r
UINT64 MtrrValidBitsMask;\r
UINT64 MtrrValidAddressMask;\r
UINT32 VariableMtrrCount;\r
- BOOLEAN ContainVariableMtrr;\r
- CHAR8 DebugMessage[256];\r
\r
MTRR_MEMORY_RANGE Ranges[\r
MTRR_NUMBER_OF_FIXED_MTRR * sizeof (UINT64) + 2 * ARRAY_SIZE (Mtrrs->Variables.Mtrr) + 1\r
MtrrGetAllMtrrs (&LocalMtrrs);\r
Mtrrs = &LocalMtrrs;\r
\r
- //\r
- // Dump RAW MTRR contents\r
- //\r
- if (OsServiceDebugPrint != NULL) {\r
- OsServiceDebugPrint (" MTRR Settings:\n");\r
- OsServiceDebugPrint (" =============\n");\r
-\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " MTRR Default Type: %016lx\n",\r
- Mtrrs->MtrrDefType\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
- }\r
-\r
- if (OsServiceDebugPrint != NULL) {\r
- for (Index = 0; Index < MTRR_NUMBER_OF_FIXED_MTRR; Index++) {\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " Fixed MTRR[%02d] : %016lx\n",\r
- Index,\r
- Mtrrs->Fixed.Mtrr[Index]\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
- }\r
-\r
- ContainVariableMtrr = FALSE;\r
- for (Index = 0; Index < VariableMtrrCount; Index++) {\r
- if ((Mtrrs->Variables.Mtrr[Index].Mask & BIT11) == 0) {\r
- //\r
- // If mask is not valid, then do not display range\r
- //\r
- continue;\r
- }\r
- ContainVariableMtrr = TRUE;\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " Variable MTRR[%02d]: Base=%016lx Mask=%016lx\n",\r
- Index,\r
- Mtrrs->Variables.Mtrr[Index].Base,\r
- Mtrrs->Variables.Mtrr[Index].Mask\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
- }\r
- if (!ContainVariableMtrr) {\r
- OsServiceDebugPrint (" Variable MTRR : None.\n");\r
- }\r
- OsServiceDebugPrint ("\n");\r
- }\r
-\r
- //\r
- // Dump MTRR setting in ranges\r
- //\r
- if (OsServiceDebugPrint != NULL) {\r
- OsServiceDebugPrint (" Memory Ranges:\n");\r
- OsServiceDebugPrint (" ====================================\n");\r
- }\r
MtrrLibInitializeMtrrMask (&MtrrValidBitsMask, &MtrrValidAddressMask);\r
Ranges[0].BaseAddress = 0;\r
Ranges[0].Length = MtrrValidBitsMask + 1;\r
);\r
\r
MtrrLibApplyFixedMtrrs (&Mtrrs->Fixed, Ranges, ARRAY_SIZE (Ranges), &RangeCount);\r
-\r
- if (OsServiceDebugPrint != NULL) {\r
- for (Index = 0; Index < RangeCount; Index++) {\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " %a:%016lx-%016lx\n",\r
- mMtrrMemoryCacheTypeShortName[Ranges[Index].Type],\r
- Ranges[Index].BaseAddress, Ranges[Index].BaseAddress + Ranges[Index].Length - 1\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
- }\r
- }\r
}\r
\r
/**\r
/**\r
Accesses HPET configuration information.\r
\r
- If the optional OsServiceDebugPrint function pointer is provided that function is\r
- used to print HPET settings.\r
-\r
- @param[in] OsServiceDebugPrint A pointer to an OS-provided debug print function\r
-\r
**/\r
VOID\r
EFIAPI\r
AccessHpetConfiguration (\r
- IN PRM_OS_SERVICE_DEBUG_PRINT OsServiceDebugPrint\r
+ VOID\r
)\r
{\r
- UINTN TimerIndex;\r
- HPET_GENERAL_CAPABILITIES_ID_REGISTER HpetGeneralCapabilities;\r
- HPET_GENERAL_CONFIGURATION_REGISTER HpetGeneralConfiguration;\r
- CHAR8 DebugMessage[256];\r
-\r
- HpetGeneralCapabilities.Uint64 = HpetRead (HPET_GENERAL_CAPABILITIES_ID_OFFSET);\r
- HpetGeneralConfiguration.Uint64 = HpetRead (HPET_GENERAL_CONFIGURATION_OFFSET);\r
-\r
- if (OsServiceDebugPrint != NULL) {\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " HPET Base Address = 0x%08x\n",\r
- HPET_BASE_ADDRESS\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
-\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " HPET_GENERAL_CAPABILITIES_ID = 0x%016lx\n",\r
- HpetGeneralCapabilities\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
-\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " HPET_GENERAL_CONFIGURATION = 0x%016lx\n",\r
- HpetGeneralConfiguration.Uint64\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
-\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " HPET_GENERAL_INTERRUPT_STATUS = 0x%016lx\n",\r
- HpetRead (HPET_GENERAL_INTERRUPT_STATUS_OFFSET)\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
-\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " HPET_MAIN_COUNTER = 0x%016lx\n",\r
- HpetRead (HPET_MAIN_COUNTER_OFFSET)\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
-\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " HPET Main Counter Period = %d (fs)\n",\r
- HpetGeneralCapabilities.Bits.CounterClockPeriod\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
-\r
- for (TimerIndex = 0; TimerIndex <= HpetGeneralCapabilities.Bits.NumberOfTimers; TimerIndex++) {\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " HPET_TIMER%d_CONFIGURATION = 0x%016lx\n",\r
- TimerIndex,\r
- HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + TimerIndex * HPET_TIMER_STRIDE)\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
-\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " HPET_TIMER%d_COMPARATOR = 0x%016lx\n",\r
- TimerIndex,\r
- HpetRead (HPET_TIMER_COMPARATOR_OFFSET + TimerIndex * HPET_TIMER_STRIDE)\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
-\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " HPET_TIMER%d_MSI_ROUTE = 0x%016lx\n",\r
- TimerIndex,\r
- HpetRead (HPET_TIMER_MSI_ROUTE_OFFSET + TimerIndex * HPET_TIMER_STRIDE)\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
- }\r
- }\r
+ HpetRead (HPET_GENERAL_CAPABILITIES_ID_OFFSET);\r
+ HpetRead (HPET_GENERAL_CONFIGURATION_OFFSET);\r
}\r
\r
/**\r
return BiosSignIdMsr.Bits.MicrocodeUpdateSignature;\r
}\r
\r
-/**\r
- Prints the microcode update signature as read from architectural MSR 0x8B.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-PrintMicrocodeUpdateSignature (\r
- IN PRM_OS_SERVICE_DEBUG_PRINT OsServiceDebugPrint\r
- )\r
-{\r
- UINT32 MicrocodeSignature;\r
- CHAR8 DebugMessage[256];\r
-\r
- if (OsServiceDebugPrint == NULL) {\r
- return;\r
- }\r
-\r
- MicrocodeSignature = GetMicrocodeSignature ();\r
-\r
- AsciiSPrint (\r
- &DebugMessage[0],\r
- ARRAY_SIZE (DebugMessage),\r
- " Signature read = 0x%x.\n",\r
- MicrocodeSignature\r
- );\r
- OsServiceDebugPrint (&DebugMessage[0]);\r
-}\r
-\r
/**\r
A sample Platform Runtime Mechanism (PRM) handler.\r
\r
return EFI_SUCCESS;\r
}\r
\r
-/**\r
- A sample Platform Runtime Mechanism (PRM) handler.\r
-\r
- This sample handler attempts to read the microcode update signature MSR and print the result to a debug message.\r
-\r
- @param[in] ParameterBuffer A pointer to the PRM handler parameter buffer\r
- @param[in] ContextBUffer A pointer to the PRM handler context buffer\r
-\r
- @retval EFI_STATUS The PRM handler executed successfully.\r
- @retval Others An error occurred in the PRM handler.\r
-\r
-**/\r
-PRM_HANDLER_EXPORT (MsrPrintMicrocodeSignaturePrmHandler)\r
-{\r
- PRM_OS_SERVICE_DEBUG_PRINT OsServiceDebugPrint;\r
-\r
- if (ParameterBuffer == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- // The OS debug print service is assumed to be at the beginning of ParameterBuffer\r
- OsServiceDebugPrint = *((PRM_OS_SERVICE_DEBUG_PRINT *) ParameterBuffer);\r
- if (OsServiceDebugPrint == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- OsServiceDebugPrint ("Hardware Access MsrAccessMicrocodeSignaturePrmHandler entry.\n");\r
- OsServiceDebugPrint (" Attempting to read the Microcode Update Signature MSR (0x8B)...\n");\r
- PrintMicrocodeUpdateSignature (OsServiceDebugPrint);\r
- OsServiceDebugPrint ("Hardware Access MsrAccessMicrocodeSignaturePrmHandler exit.\n");\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
/**\r
A sample Platform Runtime Mechanism (PRM) handler.\r
\r
**/\r
PRM_HANDLER_EXPORT (MsrAccessMtrrDumpPrmHandler)\r
{\r
- AccessAllMtrrs (NULL);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- A sample Platform Runtime Mechanism (PRM) handler.\r
-\r
- This sample handler attempts to read the current MTRR settings and print the result to a debug message.\r
-\r
- @param[in] ParameterBuffer A pointer to the PRM handler parameter buffer\r
- @param[in] ContextBUffer A pointer to the PRM handler context buffer\r
-\r
- @retval EFI_STATUS The PRM handler executed successfully.\r
- @retval Others An error occurred in the PRM handler.\r
-\r
-**/\r
-PRM_HANDLER_EXPORT (MsrPrintMtrrDumpPrmHandler)\r
-{\r
- PRM_OS_SERVICE_DEBUG_PRINT OsServiceDebugPrint;\r
-\r
- if (ParameterBuffer == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- // In the POC, the OS debug print service is assumed to be at the beginning of ParameterBuffer\r
- OsServiceDebugPrint = *((PRM_OS_SERVICE_DEBUG_PRINT *) ParameterBuffer);\r
- if (OsServiceDebugPrint == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- OsServiceDebugPrint ("Hardware Access MsrAccessMtrrDumpPrmHandler entry.\n");\r
- OsServiceDebugPrint (" Attempting to dump MTRR values:\n");\r
- AccessAllMtrrs (OsServiceDebugPrint);\r
- OsServiceDebugPrint ("Hardware Access MsrAccessMtrrDumpPrmHandler exit.\n");\r
+ AccessAllMtrrs ();\r
\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
A sample Platform Runtime Mechanism (PRM) handler.\r
\r
**/\r
PRM_HANDLER_EXPORT (MmioAccessHpetPrmHandler)\r
{\r
- AccessHpetConfiguration (NULL);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- A sample Platform Runtime Mechanism (PRM) handler.\r
-\r
- This sample handler attempts to read from a HPET MMIO resource and print the result to a debug message.\r
-\r
- @param[in] ParameterBuffer A pointer to the PRM handler parameter buffer\r
- @param[in] ContextBUffer A pointer to the PRM handler context buffer\r
-\r
- @retval EFI_STATUS The PRM handler executed successfully.\r
- @retval Others An error occurred in the PRM handler.\r
-\r
-**/\r
-PRM_HANDLER_EXPORT (MmioPrintHpetPrmHandler)\r
-{\r
- PRM_OS_SERVICE_DEBUG_PRINT OsServiceDebugPrint;\r
-\r
- if (ParameterBuffer == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- // An OS debug print service is assumed to be at the beginning of ParameterBuffer\r
- OsServiceDebugPrint = *((PRM_OS_SERVICE_DEBUG_PRINT *) ParameterBuffer);\r
- if (OsServiceDebugPrint == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- OsServiceDebugPrint ("Hardware Access MmioPrintHpetPrmHandler entry.\n");\r
- OsServiceDebugPrint (" Attempting to read HPET configuration...\n");\r
- AccessHpetConfiguration (OsServiceDebugPrint);\r
- OsServiceDebugPrint ("Hardware Access MmioPrintHpetPrmHandler exit.\n");\r
+ AccessHpetConfiguration ();\r
\r
return EFI_SUCCESS;\r
}\r
PRM_MODULE_EXPORT (\r
PRM_HANDLER_EXPORT_ENTRY (MSR_ACCESS_MICROCODE_SIGNATURE_PRM_HANDLER_GUID, MsrAccessMicrocodeSignaturePrmHandler),\r
PRM_HANDLER_EXPORT_ENTRY (MSR_ACCESS_MTRR_DUMP_PRM_HANDLER_GUID, MsrAccessMtrrDumpPrmHandler),\r
- PRM_HANDLER_EXPORT_ENTRY (MMIO_ACCESS_HPET_PRM_HANDLER_GUID, MmioAccessHpetPrmHandler),\r
- PRM_HANDLER_EXPORT_ENTRY (MSR_PRINT_MICROCODE_SIGNATURE_PRM_HANDLER_GUID, MsrPrintMicrocodeSignaturePrmHandler),\r
- PRM_HANDLER_EXPORT_ENTRY (MSR_PRINT_MTRR_DUMP_PRM_HANDLER_GUID, MsrPrintMtrrDumpPrmHandler),\r
- PRM_HANDLER_EXPORT_ENTRY (MMIO_PRINT_HPET_PRM_HANDLER_GUID, MmioPrintHpetPrmHandler)\r
+ PRM_HANDLER_EXPORT_ENTRY (MMIO_ACCESS_HPET_PRM_HANDLER_GUID, MmioAccessHpetPrmHandler)\r
);\r
\r
/**\r