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