3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 Copyright (c) 2013, ARM Ltd. All rights reserved.
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Library/UefiLib.h>
23 #include <Library/PcdLib.h>
24 #include <Library/TimerLib.h>
26 #include <Protocol/Metronome.h>
31 IN EFI_METRONOME_ARCH_PROTOCOL
*This
,
36 Interface structure for the Metronome Architectural Protocol.
38 @par Protocol Description:
39 This protocol provides access to a known time source in the platform to the
40 core. The core uses this known time source to produce core services that
41 require calibrated delays.
44 Waits for a specified number of ticks from a known time source
45 in the platform. The actual time passed between entry of this
46 function and the first tick is between 0 and TickPeriod 100 nS
47 units. If you want to guarantee that at least TickPeriod time
48 has elapsed, wait for two ticks.
51 The period of platform's known time source in 100 nS units.
52 This value on any platform must be at least 10 uS, and must not
53 exceed 200 uS. The value in this field is a constant that must
54 not be modified after the Metronome architectural protocol is
55 installed. All consumers must treat this as a read-only field.
58 EFI_METRONOME_ARCH_PROTOCOL gMetronome
= {
60 FixedPcdGet32 (PcdMetronomeTickPeriod
)
65 The WaitForTick() function waits for the number of ticks specified by
66 TickNumber from a known time source in the platform. If TickNumber of
67 ticks are detected, then EFI_SUCCESS is returned. The actual time passed
68 between entry of this function and the first tick is between 0 and
69 TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod
70 time has elapsed, wait for two ticks. This function waits for a hardware
71 event to determine when a tick occurs. It is possible for interrupt
72 processing, or exception processing to interrupt the execution of the
73 WaitForTick() function. Depending on the hardware source for the ticks, it
74 is possible for a tick to be missed. This function cannot guarantee that
75 ticks will not be missed. If a timeout occurs waiting for the specified
76 number of ticks, then EFI_TIMEOUT is returned.
78 @param This The EFI_METRONOME_ARCH_PROTOCOL instance.
79 @param TickNumber Number of ticks to wait.
81 @retval EFI_SUCCESS The wait for the number of ticks specified by TickNumber
83 @retval EFI_TIMEOUT A timeout occurred waiting for the specified number of ticks.
89 IN EFI_METRONOME_ARCH_PROTOCOL
*This
,
94 // Compute how long to stall the CPU.
95 // gMetronome.TickPeriod is in 100 ns units so it needs to be divided by 10
96 // to get it in microseconds units.
98 MicroSecondDelay (TickNumber
* gMetronome
.TickPeriod
/ 10);
103 EFI_HANDLE gMetronomeHandle
= NULL
;
108 Initialize the state information for the CPU Architectural Protocol
110 @param ImageHandle of the loaded driver
111 @param SystemTable Pointer to the System Table
113 @retval EFI_SUCCESS Protocol registered
114 @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure
115 @retval EFI_DEVICE_ERROR Hardware problems
119 MetronomeInitialize (
120 IN EFI_HANDLE ImageHandle
,
121 IN EFI_SYSTEM_TABLE
*SystemTable
127 // Do any hardware init required to make WaitForTick () to work here.
130 Status
= gBS
->InstallMultipleProtocolInterfaces (
132 &gEfiMetronomeArchProtocolGuid
, &gMetronome
,
135 ASSERT_EFI_ERROR (Status
);