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