]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/MetronomeDxe/Metronome.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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
8aff08c8
RC
46 This value on any platform must not exceed 200 uS. The value in this field\r
47 is a constant that must not be modified after the Metronome architectural\r
48 protocol is installed. All consumers must treat this as a read-only field.\r
2ef2b01e
A
49\r
50**/\r
e7108d0e 51EFI_METRONOME_ARCH_PROTOCOL gMetronome = {\r
2ef2b01e 52 WaitForTick,\r
990976ab 53 FixedPcdGet32 (PcdMetronomeTickPeriod)\r
2ef2b01e
A
54};\r
55\r
c9bf2a9e 56/**\r
57 The WaitForTick() function waits for the number of ticks specified by\r
58 TickNumber from a known time source in the platform. If TickNumber of\r
59 ticks are detected, then EFI_SUCCESS is returned. The actual time passed\r
60 between entry of this function and the first tick is between 0 and\r
61 TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod\r
62 time has elapsed, wait for two ticks. This function waits for a hardware\r
63 event to determine when a tick occurs. It is possible for interrupt\r
64 processing, or exception processing to interrupt the execution of the\r
65 WaitForTick() function. Depending on the hardware source for the ticks, it\r
66 is possible for a tick to be missed. This function cannot guarantee that\r
67 ticks will not be missed. If a timeout occurs waiting for the specified\r
68 number of ticks, then EFI_TIMEOUT is returned.\r
69\r
70 @param This The EFI_METRONOME_ARCH_PROTOCOL instance.\r
71 @param TickNumber Number of ticks to wait.\r
72\r
73 @retval EFI_SUCCESS The wait for the number of ticks specified by TickNumber\r
74 succeeded.\r
75 @retval EFI_TIMEOUT A timeout occurred waiting for the specified number of ticks.\r
76\r
77**/\r
78EFI_STATUS\r
79EFIAPI\r
80WaitForTick (\r
81 IN EFI_METRONOME_ARCH_PROTOCOL *This,\r
82 IN UINT32 TickNumber\r
83 )\r
84{\r
85 //\r
86 // Compute how long to stall the CPU.\r
87 // gMetronome.TickPeriod is in 100 ns units so it needs to be divided by 10\r
88 // to get it in microseconds units.\r
89 //\r
90 MicroSecondDelay (TickNumber * gMetronome.TickPeriod / 10);\r
91 return EFI_SUCCESS;\r
92}\r
93\r
2ef2b01e
A
94EFI_HANDLE gMetronomeHandle = NULL;\r
95\r
2ef2b01e
A
96/**\r
97 Initialize the state information for the CPU Architectural Protocol\r
98\r
99 @param ImageHandle of the loaded driver\r
100 @param SystemTable Pointer to the System Table\r
101\r
102 @retval EFI_SUCCESS Protocol registered\r
103 @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure\r
104 @retval EFI_DEVICE_ERROR Hardware problems\r
105\r
106**/\r
107EFI_STATUS\r
7609c047 108EFIAPI\r
2ef2b01e 109MetronomeInitialize (\r
e7108d0e
MK
110 IN EFI_HANDLE ImageHandle,\r
111 IN EFI_SYSTEM_TABLE *SystemTable\r
2ef2b01e
A
112 )\r
113{\r
114 EFI_STATUS Status;\r
c9bf2a9e 115\r
2ef2b01e
A
116 //\r
117 // Do any hardware init required to make WaitForTick () to work here.\r
118 //\r
119\r
120 Status = gBS->InstallMultipleProtocolInterfaces (\r
121 &gMetronomeHandle,\r
e7108d0e
MK
122 &gEfiMetronomeArchProtocolGuid,\r
123 &gMetronome,\r
2ef2b01e
A
124 NULL\r
125 );\r
126 ASSERT_EFI_ERROR (Status);\r
127\r
128 return Status;\r
129}\r