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