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