]>
Commit | Line | Data |
---|---|---|
804405e7 | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006 - 2008, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | Metronome.c\r | |
15 | \r | |
16 | Abstract:\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 | |
37 | EFI_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 | |
46 | EFI_STATUS\r | |
47 | EFIAPI\r | |
48 | UnixMetronomeDriverWaitForTick (\r | |
49 | IN EFI_METRONOME_ARCH_PROTOCOL *This,\r | |
50 | IN UINT32 TickNumber\r | |
51 | )\r | |
52 | /*++\r | |
53 | \r | |
54 | Routine 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 | |
69 | Arguments:\r | |
70 | \r | |
71 | This - The EFI_METRONOME_ARCH_PROTOCOL instance.\r | |
72 | TickNumber - Number of ticks to wait.\r | |
73 | \r | |
74 | Returns:\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 | |
94 | EFI_STATUS\r | |
95 | EFIAPI\r | |
96 | UnixMetronomeDriverInitialize (\r | |
97 | IN EFI_HANDLE ImageHandle,\r | |
98 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
99 | )\r | |
100 | /*++\r | |
101 | \r | |
102 | Routine Description:\r | |
103 | \r | |
104 | Initialize the Metronome Architectural Protocol driver\r | |
105 | \r | |
106 | Arguments:\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 | |
113 | Returns:\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 |