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