]> git.proxmox.com Git - mirror_edk2.git/blame - UnixPkg/MetronomeDxe/Metronome.c
Update the copyright notice format
[mirror_edk2.git] / UnixPkg / MetronomeDxe / Metronome.c
CommitLineData
804405e7 1/*++\r
2\r
f9b8ab56
HT
3Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials\r
804405e7 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
18 UNIX Emulation Metronome Architectural Protocol Driver as defined in DXE CIS\r
19\r
20--*/\r
21#include "PiDxe.h"\r
22#include "UnixDxe.h"\r
23#include <Protocol/Metronome.h>\r
24#include "Metronome.h"\r
25\r
26#include <Library/BaseLib.h>\r
27#include <Library/DebugLib.h>\r
28#include <Library/UefiLib.h>\r
29#include <Library/UefiDriverEntryPoint.h>\r
30#include <Library/UnixLib.h>\r
31#include <Library/MemoryAllocationLib.h>\r
32#include <Library/UefiBootServicesTableLib.h>\r
33\r
34//\r
35// Global Variables\r
36//\r
37EFI_METRONOME_ARCH_PROTOCOL mMetronome = {\r
38 UnixMetronomeDriverWaitForTick,\r
39 TICK_PERIOD\r
40};\r
41\r
42//\r
43// Worker Functions\r
44//\r
45\r
46EFI_STATUS\r
47EFIAPI\r
48UnixMetronomeDriverWaitForTick (\r
49 IN EFI_METRONOME_ARCH_PROTOCOL *This,\r
50 IN UINT32 TickNumber\r
51 )\r
52/*++\r
53\r
54Routine Description:\r
55\r
56 The WaitForTick() function waits for the number of ticks specified by\r
57 TickNumber from a known time source in the platform. If TickNumber of\r
58 ticks are detected, then EFI_SUCCESS is returned. The actual time passed\r
59 between entry of this function and the first tick is between 0 and\r
60 TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod\r
61 time has elapsed, wait for two ticks. This function waits for a hardware\r
62 event to determine when a tick occurs. It is possible for interrupt\r
63 processing, or exception processing to interrupt the execution of the\r
64 WaitForTick() function. Depending on the hardware source for the ticks, it\r
65 is possible for a tick to be missed. This function cannot guarantee that\r
66 ticks will not be missed. If a timeout occurs waiting for the specified\r
67 number of ticks, then EFI_TIMEOUT is returned.\r
68\r
69Arguments:\r
70\r
71 This - The EFI_METRONOME_ARCH_PROTOCOL instance.\r
72 TickNumber - Number of ticks to wait.\r
73\r
74Returns:\r
75\r
76 EFI_SUCCESS - The wait for the number of ticks specified by TickNumber\r
77 succeeded.\r
78\r
79--*/\r
80{\r
81 UINT64 SleepTime;\r
82\r
83 //\r
84 // Calculate the time to sleep. Win API smallest unit to sleep is 1 millisec\r
85 // Tick Period is in 100ns units, divide by 10000 to convert to ms\r
86 //\r
87 SleepTime = DivU64x32 (MultU64x32 ((UINT64) TickNumber, TICK_PERIOD) + 9999, 10000);\r
88 gUnix->Sleep ((UINT32) SleepTime);\r
89\r
90 return EFI_SUCCESS;\r
91}\r
92\r
93\r
94EFI_STATUS\r
95EFIAPI\r
96UnixMetronomeDriverInitialize (\r
97 IN EFI_HANDLE ImageHandle,\r
98 IN EFI_SYSTEM_TABLE *SystemTable\r
99 )\r
100/*++\r
101\r
102Routine Description:\r
103\r
104 Initialize the Metronome Architectural Protocol driver\r
105\r
106Arguments:\r
107\r
108 ImageHandle - ImageHandle of the loaded driver\r
109\r
110\r
111 SystemTable - Pointer to the System Table\r
112\r
113Returns:\r
114\r
115 EFI_SUCCESS - Metronome Architectural Protocol created\r
116\r
117 EFI_OUT_OF_RESOURCES - Not enough resources available to initialize driver.\r
118\r
119 EFI_DEVICE_ERROR - A device error occured attempting to initialize the driver.\r
120\r
121--*/\r
122{\r
123 EFI_STATUS Status;\r
124 EFI_HANDLE Handle;\r
125\r
126\r
127 //\r
128 // Install the Metronome Architectural Protocol onto a new handle\r
129 //\r
130 Handle = NULL;\r
131 DEBUG ((EFI_D_ERROR, "*******************file %d line %d\n", __FUNCTION__, __LINE__));\r
132 Status = gBS->InstallProtocolInterface (\r
133 &Handle,\r
134 &gEfiMetronomeArchProtocolGuid,\r
135 EFI_NATIVE_INTERFACE,\r
136 &mMetronome\r
137 );\r
138\r
139 return Status;\r
140}\r