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