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