diff --git a/DuetPkg/DuetPkg.dsc b/DuetPkg/DuetPkg.dsc index bfcc6649f6..a276746f4c 100644 --- a/DuetPkg/DuetPkg.dsc +++ b/DuetPkg/DuetPkg.dsc @@ -17,7 +17,7 @@ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf - ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf + ReportStatusCodeLib|DuetPkg/Library/DuetDxeReportStatusCodeLib/DuetDxeReportStatusCodeLib.inf UefiLib|MdePkg/Library/UefiLib/UefiLib.inf UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf @@ -29,7 +29,6 @@ UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf - BaseUefiTianoDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf PlatformBdsLib|DuetPkg/Library/DuetBdsLib/PlatformBds.inf IfrSupportLib|MdeModulePkg/Library/UefiIfrSupportLib/UefiIfrSupportLib.inf @@ -48,17 +47,16 @@ IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf TimerLib|DuetPkg/Library/DuetTimerLib/DuetTimerLib.inf UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf [LibraryClasses.common.DXE_DRIVER] MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf - ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf SerialPortLib|DuetPkg/Library/DuetSerialIoLib/DuetSerialIoLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf - ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf @@ -76,7 +74,6 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf - ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf SerialPortLib|DuetPkg/Library/DuetSerialIoLib/DuetSerialIoLib.inf IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf @@ -85,13 +82,11 @@ MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf SerialPortLib|DuetPkg/Library/DuetSerialIoLib/DuetSerialIoLib.inf DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf - ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf [LibraryClasses.common.UEFI_APPLICATION] MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf SerialPortLib|DuetPkg/Library/DuetSerialIoLib/DuetSerialIoLib.inf DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf - ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf [PcdsFixedAtBuild] gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07 diff --git a/DuetPkg/LegacyMetronome/Metronome.inf b/DuetPkg/LegacyMetronome/Metronome.inf index d97b67f334..9f061d27b9 100644 --- a/DuetPkg/LegacyMetronome/Metronome.inf +++ b/DuetPkg/LegacyMetronome/Metronome.inf @@ -35,7 +35,8 @@ UefiDriverEntryPoint DebugLib UefiBootServicesTableLib - + IoLib + [Sources.common] Metronome.c Metronome.h diff --git a/DuetPkg/Library/DuetDxeReportStatusCodeLib/DuetDxeReportStatusCodeLib.inf b/DuetPkg/Library/DuetDxeReportStatusCodeLib/DuetDxeReportStatusCodeLib.inf index ed432ea67f..11dcbcb69f 100644 --- a/DuetPkg/Library/DuetDxeReportStatusCodeLib/DuetDxeReportStatusCodeLib.inf +++ b/DuetPkg/Library/DuetDxeReportStatusCodeLib/DuetDxeReportStatusCodeLib.inf @@ -36,7 +36,6 @@ DxeSupport.c ReportStatusCodeLibInternal.h - [Packages] MdePkg/MdePkg.dec IntelFrameworkPkg/IntelFrameworkPkg.dec diff --git a/DuetPkg/Library/DuetTimerLib/DuetTimerLib.inf b/DuetPkg/Library/DuetTimerLib/DuetTimerLib.inf index 9a3af0afb6..6d841645b0 100644 --- a/DuetPkg/Library/DuetTimerLib/DuetTimerLib.inf +++ b/DuetPkg/Library/DuetTimerLib/DuetTimerLib.inf @@ -22,7 +22,7 @@ INF_VERSION = 0x00010005 BASE_NAME = DuetTimerLib FILE_GUID = 5F9A01F5-726E-4f59-809D-887F4766734E - MODULE_TYPE = BASE + MODULE_TYPE = DXE_DRIVER VERSION_STRING = 1.0 LIBRARY_CLASS = TimerLib EDK_RELEASE_VERSION = 0x00020000 @@ -43,26 +43,10 @@ [Packages] MdePkg/MdePkg.dec - [LibraryClasses] BaseLib - -[LibraryClasses.IA32] - PcdLib - IoLib - -[LibraryClasses.X64] - PcdLib - IoLib - -[LibraryClasses.IPF] DebugLib - PalLib - - -[Pcd.IA32] - gEfiMdePkgTokenSpaceGuid.PcdFSBClock - -[Pcd.X64] - gEfiMdePkgTokenSpaceGuid.PcdFSBClock + UefiBootServicesTableLib +[Protocols] + gEfiMetronomeArchProtocolGuid # ALWAYS_CONSUMED diff --git a/DuetPkg/Library/DuetTimerLib/X86TimerLib.c b/DuetPkg/Library/DuetTimerLib/X86TimerLib.c index 9c8d46fe70..13df34fc34 100644 --- a/DuetPkg/Library/DuetTimerLib/X86TimerLib.c +++ b/DuetPkg/Library/DuetTimerLib/X86TimerLib.c @@ -15,107 +15,26 @@ #include #include #include -#include #include -#include +#include - -// -// The following array is used in calculating the frequency of local APIC -// timer. Refer to IA-32 developers' manual for more details. -// -GLOBAL_REMOVE_IF_UNREFERENCED -CONST UINT8 mTimerLibLocalApicDivisor[] = { - 0x02, 0x04, 0x08, 0x10, - 0x02, 0x04, 0x08, 0x10, - 0x20, 0x40, 0x80, 0x01, - 0x20, 0x40, 0x80, 0x01 -}; +#include /** - Internal function to retrieve the base address of local APIC. +EFI_METRONOME_ARCH_PROTOCOL *gDuetMetronome = NULL; - Internal function to retrieve the base address of local APIC. - - @return The base address of local APIC - -**/ -UINTN -InternalX86GetApicBase ( - VOID - ) +EFI_METRONOME_ARCH_PROTOCOL* +GetMetronomeArchProtocol ( + VOID + ) { - return (UINTN)AsmMsrBitFieldRead64 (27, 12, 35) << 12; -} - -/** - Internal function to return the frequency of the local APIC timer. - - Internal function to return the frequency of the local APIC timer. - - @param ApicBase The base address of memory mapped registers of local APIC. - - @return The frequency of the timer in Hz. - + if (gDuetMetronome == NULL) { + gBS->LocateProtocol (&gEfiMetronomeArchProtocolGuid, NULL, (VOID**) &gDuetMetronome); + } + + return gDuetMetronome; +} **/ -UINT32 -InternalX86GetTimerFrequency ( - IN UINTN ApicBase - ) -{ - return - PcdGet32(PcdFSBClock) / - mTimerLibLocalApicDivisor[MmioBitFieldRead32 (ApicBase + 0x3e0, 0, 3)]; -} - -/** - Internal function to read the current tick counter of local APIC. - - Internal function to read the current tick counter of local APIC. - - @param ApicBase The base address of memory mapped registers of local APIC. - - @return The tick counter read. - -**/ -INT32 -InternalX86GetTimerTick ( - IN UINTN ApicBase - ) -{ - return MmioRead32 (ApicBase + 0x390); -} - -/** - Stalls the CPU for at least the given number of ticks. - - Stalls the CPU for at least the given number of ticks. It's invoked by - MicroSecondDelay() and NanoSecondDelay(). - - @param ApicBase The base address of memory mapped registers of local APIC. - @param Delay A period of time to delay in ticks. - -**/ -VOID -InternalX86Delay ( - IN UINTN ApicBase, - IN UINT32 Delay - ) -{ - INT32 Ticks; - - // - // The target timer count is calculated here - // - Ticks = InternalX86GetTimerTick (ApicBase) - Delay; - - // - // Wait until time out - // Delay > 2^31 could not be handled by this function - // Timer wrap-arounds are handled correctly by this function - // - while (InternalX86GetTimerTick (ApicBase) - Ticks >= 0); -} /** Stalls the CPU for at least the given number of microseconds. @@ -133,19 +52,36 @@ MicroSecondDelay ( IN UINTN MicroSeconds ) { - UINTN ApicBase; + gBS->Stall (MicroSeconds); +/** + EFI_METRONOME_ARCH_PROTOCOL *mMetronome; + UINT32 Counter; + UINTN Remainder; + + if ((mMetronome = GetMetronomeArchProtocol()) == NULL) { + return MicroSeconds; + } + + // + // Calculate the number of ticks by dividing the number of microseconds by + // the TickPeriod. + // Calculation is based on 100ns unit. + // + Counter = (UINT32) DivU64x32Remainder ( + MicroSeconds * 10, + mMetronome->TickPeriod, + &Remainder + ); + // + // Call WaitForTick for Counter + 1 ticks to try to guarantee Counter tick + // periods, thus attempting to ensure Microseconds of stall time. + // + if (Remainder != 0) { + Counter++; + } - ApicBase = InternalX86GetApicBase (); - InternalX86Delay ( - ApicBase, - (UINT32)DivU64x32 ( - MultU64x64 ( - InternalX86GetTimerFrequency (ApicBase), - MicroSeconds - ), - 1000000u - ) - ); + mMetronome->WaitForTick (mMetronome, Counter); +**/ return MicroSeconds; } @@ -165,20 +101,11 @@ NanoSecondDelay ( IN UINTN NanoSeconds ) { - UINTN ApicBase; - - ApicBase = InternalX86GetApicBase (); - InternalX86Delay ( - ApicBase, - (UINT32)DivU64x32 ( - MultU64x64 ( - InternalX86GetTimerFrequency (ApicBase), - NanoSeconds - ), - 1000000000u - ) - ); - return NanoSeconds; + // + // Duet platform need *not* this interface. + // + //ASSERT (FALSE); + return 0; } /** @@ -199,7 +126,11 @@ GetPerformanceCounter ( VOID ) { - return (UINT64)(UINT32)InternalX86GetTimerTick (InternalX86GetApicBase ()); + // + // Duet platform need *not* this interface. + // + //ASSERT (FALSE); + return 0; } /** @@ -232,17 +163,9 @@ GetPerformanceCounterProperties ( OUT UINT64 *EndValue OPTIONAL ) { - UINTN ApicBase; - - ApicBase = InternalX86GetApicBase (); - - if (StartValue != NULL) { - *StartValue = MmioRead32 (ApicBase + 0x380); - } - - if (EndValue != NULL) { - *EndValue = 0; - } - - return (UINT64) InternalX86GetTimerFrequency (ApicBase);; + // + // Duet platform need *not* this interface. + // + //ASSERT (FALSE); + return 0; }