ArmPkg: only attempt buildin MmCommunicationDxe for AArch64
[mirror_edk2.git] / EmbeddedPkg / MetronomeDxe / Metronome.c
1 /** @file
2
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 Copyright (c) 2013, ARM Ltd. All rights reserved.
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <PiDxe.h>
11
12 #include <Library/BaseLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/UefiBootServicesTableLib.h>
16 #include <Library/UefiLib.h>
17 #include <Library/PcdLib.h>
18 #include <Library/TimerLib.h>
19
20 #include <Protocol/Metronome.h>
21
22 EFI_STATUS
23 EFIAPI
24 WaitForTick (
25 IN EFI_METRONOME_ARCH_PROTOCOL *This,
26 IN UINT32 TickNumber
27 );
28
29 /**
30 Interface structure for the Metronome Architectural Protocol.
31
32 @par Protocol Description:
33 This protocol provides access to a known time source in the platform to the
34 core. The core uses this known time source to produce core services that
35 require calibrated delays.
36
37 @param WaitForTick
38 Waits for a specified number of ticks from a known time source
39 in the platform. The actual time passed between entry of this
40 function and the first tick is between 0 and TickPeriod 100 nS
41 units. If you want to guarantee that at least TickPeriod time
42 has elapsed, wait for two ticks.
43
44 @param TickPeriod
45 The period of platform's known time source in 100 nS units.
46 This value on any platform must be at least 10 uS, and must not
47 exceed 200 uS. The value in this field is a constant that must
48 not be modified after the Metronome architectural protocol is
49 installed. All consumers must treat this as a read-only field.
50
51 **/
52 EFI_METRONOME_ARCH_PROTOCOL gMetronome = {
53 WaitForTick,
54 FixedPcdGet32 (PcdMetronomeTickPeriod)
55 };
56
57
58 /**
59 The WaitForTick() function waits for the number of ticks specified by
60 TickNumber from a known time source in the platform. If TickNumber of
61 ticks are detected, then EFI_SUCCESS is returned. The actual time passed
62 between entry of this function and the first tick is between 0 and
63 TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod
64 time has elapsed, wait for two ticks. This function waits for a hardware
65 event to determine when a tick occurs. It is possible for interrupt
66 processing, or exception processing to interrupt the execution of the
67 WaitForTick() function. Depending on the hardware source for the ticks, it
68 is possible for a tick to be missed. This function cannot guarantee that
69 ticks will not be missed. If a timeout occurs waiting for the specified
70 number of ticks, then EFI_TIMEOUT is returned.
71
72 @param This The EFI_METRONOME_ARCH_PROTOCOL instance.
73 @param TickNumber Number of ticks to wait.
74
75 @retval EFI_SUCCESS The wait for the number of ticks specified by TickNumber
76 succeeded.
77 @retval EFI_TIMEOUT A timeout occurred waiting for the specified number of ticks.
78
79 **/
80 EFI_STATUS
81 EFIAPI
82 WaitForTick (
83 IN EFI_METRONOME_ARCH_PROTOCOL *This,
84 IN UINT32 TickNumber
85 )
86 {
87 //
88 // Compute how long to stall the CPU.
89 // gMetronome.TickPeriod is in 100 ns units so it needs to be divided by 10
90 // to get it in microseconds units.
91 //
92 MicroSecondDelay (TickNumber * gMetronome.TickPeriod / 10);
93 return EFI_SUCCESS;
94 }
95
96
97 EFI_HANDLE gMetronomeHandle = NULL;
98
99
100
101 /**
102 Initialize the state information for the CPU Architectural Protocol
103
104 @param ImageHandle of the loaded driver
105 @param SystemTable Pointer to the System Table
106
107 @retval EFI_SUCCESS Protocol registered
108 @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure
109 @retval EFI_DEVICE_ERROR Hardware problems
110
111 **/
112 EFI_STATUS
113 EFIAPI
114 MetronomeInitialize (
115 IN EFI_HANDLE ImageHandle,
116 IN EFI_SYSTEM_TABLE *SystemTable
117 )
118 {
119 EFI_STATUS Status;
120
121 //
122 // Do any hardware init required to make WaitForTick () to work here.
123 //
124
125 Status = gBS->InstallMultipleProtocolInterfaces (
126 &gMetronomeHandle,
127 &gEfiMetronomeArchProtocolGuid, &gMetronome,
128 NULL
129 );
130 ASSERT_EFI_ERROR (Status);
131
132 return Status;
133 }
134