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