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