]>
Commit | Line | Data |
---|---|---|
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 | |
60274cca | 6 | This program and the accompanying materials\r |
2ef2b01e A |
7 | are licensed and made available under the terms and conditions of the BSD License\r |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include <PiDxe.h>\r | |
17 | \r | |
18 | #include <Library/BaseLib.h>\r | |
19 | #include <Library/DebugLib.h>\r | |
20 | #include <Library/BaseMemoryLib.h>\r | |
21 | #include <Library/UefiBootServicesTableLib.h>\r | |
22 | #include <Library/UefiLib.h>\r | |
23 | #include <Library/PcdLib.h>\r | |
24 | #include <Library/TimerLib.h>\r | |
25 | \r | |
26 | #include <Protocol/Metronome.h>\r | |
27 | \r | |
2ef2b01e A |
28 | EFI_STATUS\r |
29 | EFIAPI\r | |
30 | WaitForTick (\r | |
31 | IN EFI_METRONOME_ARCH_PROTOCOL *This,\r | |
32 | IN UINT32 TickNumber\r | |
c9bf2a9e | 33 | );\r |
2ef2b01e A |
34 | \r |
35 | /**\r | |
7ca9e5a4 | 36 | Interface structure for the Metronome Architectural Protocol.\r |
2ef2b01e A |
37 | \r |
38 | @par Protocol Description:\r | |
39 | This protocol provides access to a known time source in the platform to the\r | |
c9bf2a9e | 40 | core. The core uses this known time source to produce core services that\r |
41 | require calibrated delays.\r | |
2ef2b01e A |
42 | \r |
43 | @param WaitForTick\r | |
c9bf2a9e | 44 | Waits for a specified number of ticks from a known time source\r |
45 | in the platform. The actual time passed between entry of this\r | |
46 | function and the first tick is between 0 and TickPeriod 100 nS\r | |
47 | units. If you want to guarantee that at least TickPeriod time\r | |
2ef2b01e A |
48 | has elapsed, wait for two ticks.\r |
49 | \r | |
50 | @param TickPeriod\r | |
c9bf2a9e | 51 | The period of platform's known time source in 100 nS units.\r |
52 | This value on any platform must be at least 10 uS, and must not\r | |
53 | exceed 200 uS. The value in this field is a constant that must\r | |
54 | not be modified after the Metronome architectural protocol is\r | |
2ef2b01e A |
55 | installed. All consumers must treat this as a read-only field.\r |
56 | \r | |
57 | **/\r | |
58 | EFI_METRONOME_ARCH_PROTOCOL gMetronome = {\r | |
59 | WaitForTick,\r | |
990976ab | 60 | FixedPcdGet32 (PcdMetronomeTickPeriod)\r |
2ef2b01e A |
61 | };\r |
62 | \r | |
63 | \r | |
c9bf2a9e | 64 | /**\r |
65 | The WaitForTick() function waits for the number of ticks specified by\r | |
66 | TickNumber from a known time source in the platform. If TickNumber of\r | |
67 | ticks are detected, then EFI_SUCCESS is returned. The actual time passed\r | |
68 | between entry of this function and the first tick is between 0 and\r | |
69 | TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod\r | |
70 | time has elapsed, wait for two ticks. This function waits for a hardware\r | |
71 | event to determine when a tick occurs. It is possible for interrupt\r | |
72 | processing, or exception processing to interrupt the execution of the\r | |
73 | WaitForTick() function. Depending on the hardware source for the ticks, it\r | |
74 | is possible for a tick to be missed. This function cannot guarantee that\r | |
75 | ticks will not be missed. If a timeout occurs waiting for the specified\r | |
76 | number of ticks, then EFI_TIMEOUT is returned.\r | |
77 | \r | |
78 | @param This The EFI_METRONOME_ARCH_PROTOCOL instance.\r | |
79 | @param TickNumber Number of ticks to wait.\r | |
80 | \r | |
81 | @retval EFI_SUCCESS The wait for the number of ticks specified by TickNumber\r | |
82 | succeeded.\r | |
83 | @retval EFI_TIMEOUT A timeout occurred waiting for the specified number of ticks.\r | |
84 | \r | |
85 | **/\r | |
86 | EFI_STATUS\r | |
87 | EFIAPI\r | |
88 | WaitForTick (\r | |
89 | IN EFI_METRONOME_ARCH_PROTOCOL *This,\r | |
90 | IN UINT32 TickNumber\r | |
91 | )\r | |
92 | {\r | |
93 | //\r | |
94 | // Compute how long to stall the CPU.\r | |
95 | // gMetronome.TickPeriod is in 100 ns units so it needs to be divided by 10\r | |
96 | // to get it in microseconds units.\r | |
97 | //\r | |
98 | MicroSecondDelay (TickNumber * gMetronome.TickPeriod / 10);\r | |
99 | return EFI_SUCCESS;\r | |
100 | }\r | |
101 | \r | |
102 | \r | |
2ef2b01e A |
103 | EFI_HANDLE gMetronomeHandle = NULL;\r |
104 | \r | |
105 | \r | |
106 | \r | |
107 | /**\r | |
108 | Initialize the state information for the CPU Architectural Protocol\r | |
109 | \r | |
110 | @param ImageHandle of the loaded driver\r | |
111 | @param SystemTable Pointer to the System Table\r | |
112 | \r | |
113 | @retval EFI_SUCCESS Protocol registered\r | |
114 | @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure\r | |
115 | @retval EFI_DEVICE_ERROR Hardware problems\r | |
116 | \r | |
117 | **/\r | |
118 | EFI_STATUS\r | |
119 | MetronomeInitialize (\r | |
120 | IN EFI_HANDLE ImageHandle,\r | |
121 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
122 | )\r | |
123 | {\r | |
124 | EFI_STATUS Status;\r | |
c9bf2a9e | 125 | \r |
2ef2b01e A |
126 | //\r |
127 | // Do any hardware init required to make WaitForTick () to work here.\r | |
128 | //\r | |
129 | \r | |
130 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
131 | &gMetronomeHandle,\r | |
132 | &gEfiMetronomeArchProtocolGuid, &gMetronome,\r | |
133 | NULL\r | |
134 | );\r | |
135 | ASSERT_EFI_ERROR (Status);\r | |
136 | \r | |
137 | return Status;\r | |
138 | }\r | |
139 | \r |