delete dxs file
[mirror_edk2.git] / Nt32Pkg / MonotonicCounterRuntimeDxe / Metronome.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 Metronome.c
15
16 Abstract:
17
18 NT Emulation Metronome Architectural Protocol Driver as defined in DXE CIS
19
20 --*/
21
22 //
23 // Include common header file for this module.
24 //
25 #include "CommonHeader.h"
26
27 #include "Metronome.h"
28
29 //
30 // Global Variables
31 //
32 EFI_METRONOME_ARCH_PROTOCOL mMetronome = {
33 WinNtMetronomeDriverWaitForTick,
34 TICK_PERIOD
35 };
36
37 //
38 // Worker Functions
39 //
40
41 EFI_STATUS
42 EFIAPI
43 WinNtMetronomeDriverWaitForTick (
44 IN EFI_METRONOME_ARCH_PROTOCOL *This,
45 IN UINT32 TickNumber
46 )
47 /*++
48
49 Routine Description:
50
51 The WaitForTick() function waits for the number of ticks specified by
52 TickNumber from a known time source in the platform. If TickNumber of
53 ticks are detected, then EFI_SUCCESS is returned. The actual time passed
54 between entry of this function and the first tick is between 0 and
55 TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod
56 time has elapsed, wait for two ticks. This function waits for a hardware
57 event to determine when a tick occurs. It is possible for interrupt
58 processing, or exception processing to interrupt the execution of the
59 WaitForTick() function. Depending on the hardware source for the ticks, it
60 is possible for a tick to be missed. This function cannot guarantee that
61 ticks will not be missed. If a timeout occurs waiting for the specified
62 number of ticks, then EFI_TIMEOUT is returned.
63
64 Arguments:
65
66 This - The EFI_METRONOME_ARCH_PROTOCOL instance.
67 TickNumber - Number of ticks to wait.
68
69 Returns:
70
71 EFI_SUCCESS - The wait for the number of ticks specified by TickNumber
72 succeeded.
73
74 --*/
75 {
76 UINT64 SleepTime;
77
78 //
79 // Calculate the time to sleep. Win API smallest unit to sleep is 1 millisec
80 // Tick Period is in 100ns units, divide by 10000 to convert to ms
81 //
82 SleepTime = DivU64x32 (MultU64x32 ((UINT64) TickNumber, TICK_PERIOD) + 9999, 10000);
83 gWinNt->Sleep ((UINT32) SleepTime);
84
85 return EFI_SUCCESS;
86 }
87
88
89 EFI_STATUS
90 EFIAPI
91 WinNtMetronomeDriverInitialize (
92 IN EFI_HANDLE ImageHandle,
93 IN EFI_SYSTEM_TABLE *SystemTable
94 )
95 /*++
96
97 Routine Description:
98
99 Initialize the Metronome Architectural Protocol driver
100
101 Arguments:
102
103 ImageHandle - ImageHandle of the loaded driver
104
105
106 SystemTable - Pointer to the System Table
107
108 Returns:
109
110 EFI_SUCCESS - Metronome Architectural Protocol created
111
112 EFI_OUT_OF_RESOURCES - Not enough resources available to initialize driver.
113
114 EFI_DEVICE_ERROR - A device error occured attempting to initialize the driver.
115
116 --*/
117 {
118 EFI_STATUS Status;
119 EFI_HANDLE Handle;
120
121
122 //
123 // Install the Metronome Architectural Protocol onto a new handle
124 //
125 Handle = NULL;
126 Status = gBS->InstallProtocolInterface (
127 &Handle,
128 &gEfiMetronomeArchProtocolGuid,
129 EFI_NATIVE_INTERFACE,
130 &mMetronome
131 );
132
133 return Status;
134 }