]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiRuntimeLib/RuntimeLib.c
Code and comments have been checked with spec.
[mirror_edk2.git] / MdePkg / Library / UefiRuntimeLib / RuntimeLib.c
1 /** @file
2 UEFI Runtime Library implementation for non IPF processor types.
3
4 Copyright (c) 2006 - 2008 Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "RuntimeLibInternal.h"
16
17 ///
18 /// Driver Lib Module Globals
19 ///
20
21 EFI_EVENT mEfiVirtualNotifyEvent;
22 EFI_EVENT mEfiExitBootServicesEvent;
23 BOOLEAN mEfiGoneVirtual = FALSE;
24 BOOLEAN mEfiAtRuntime = FALSE;
25 EFI_RUNTIME_SERVICES *mRT;
26
27 /**
28 Set AtRuntime flag as TRUE after ExitBootServices.
29
30 @param[in] Event The Event that is being processed
31 @param[in] Context Event Context
32 **/
33 VOID
34 EFIAPI
35 RuntimeLibExitBootServicesEvent (
36 IN EFI_EVENT Event,
37 IN VOID *Context
38 )
39 {
40 //
41 // Clear out BootService globals
42 //
43 gBS = NULL;
44
45 mEfiAtRuntime = TRUE;
46 }
47
48 /**
49 Fixup internal data so that EFI can be call in virtual mode.
50 Call the passed in Child Notify event and convert any pointers in
51 lib to virtual mode.
52
53 @param[in] Event The Event that is being processed
54 @param[in] Context Event Context
55 **/
56 VOID
57 EFIAPI
58 RuntimeLibVirtualNotifyEvent (
59 IN EFI_EVENT Event,
60 IN VOID *Context
61 )
62 {
63 //
64 // Update global for Runtime Services Table and IO
65 //
66 EfiConvertPointer (0, (VOID **) &mRT);
67
68 mEfiGoneVirtual = TRUE;
69 }
70
71 /**
72 Intialize runtime Driver Lib if it has not yet been initialized.
73 It will ASSERT() if gRT is NULL or gBS is NULL.
74 It will ASSERT() if that operation fails.
75
76 @param[in] ImageHandle The firmware allocated handle for the EFI image.
77 @param[in] SystemTable A pointer to the EFI System Table.
78
79 @return EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.
80 **/
81 EFI_STATUS
82 EFIAPI
83 RuntimeDriverLibConstruct (
84 IN EFI_HANDLE ImageHandle,
85 IN EFI_SYSTEM_TABLE *SystemTable
86 )
87 {
88 EFI_STATUS Status;
89
90 ASSERT (gRT != NULL);
91 ASSERT (gBS != NULL);
92
93 mRT = gRT;
94 //
95 // Register SetVirtualAddressMap () notify function
96 //
97 Status = gBS->CreateEvent (
98 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
99 TPL_NOTIFY,
100 RuntimeLibVirtualNotifyEvent,
101 NULL,
102 &mEfiVirtualNotifyEvent
103 );
104
105 ASSERT_EFI_ERROR (Status);
106
107 Status = gBS->CreateEvent (
108 EVT_SIGNAL_EXIT_BOOT_SERVICES,
109 TPL_NOTIFY,
110 RuntimeLibExitBootServicesEvent,
111 NULL,
112 &mEfiExitBootServicesEvent
113 );
114
115 ASSERT_EFI_ERROR (Status);
116
117 return Status;
118 }
119
120 /**
121 If a runtime driver exits with an error, it must call this routine
122 to free the allocated resource before the exiting.
123 It will ASSERT() if gBS is NULL.
124 It will ASSERT() if that operation fails.
125
126 @param[in] ImageHandle The firmware allocated handle for the EFI image.
127 @param[in] SystemTable A pointer to the EFI System Table.
128
129 @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully
130 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all
131 **/
132 EFI_STATUS
133 EFIAPI
134 RuntimeDriverLibDeconstruct (
135 IN EFI_HANDLE ImageHandle,
136 IN EFI_SYSTEM_TABLE *SystemTable
137 )
138 {
139 EFI_STATUS Status;
140
141 //
142 // Close SetVirtualAddressMap () notify function
143 //
144 ASSERT (gBS != NULL);
145 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);
146 ASSERT_EFI_ERROR (Status);
147
148 Status = gBS->CloseEvent (mEfiExitBootServicesEvent);
149 ASSERT_EFI_ERROR (Status);
150
151 return Status;
152 }
153
154 /**
155 This function allows the caller to determine if UEFI ExitBootServices() has been called.
156
157 This function returns TRUE after all the EVT_SIGNAL_EXIT_BOOT_SERVICES functions have
158 executed as a result of the OS calling ExitBootServices(). Prior to this time FALSE
159 is returned. This function is used by runtime code to decide it is legal to access
160 services that go away after ExitBootServices().
161
162 @retval TRUE The system has finished executing the EVT_SIGNAL_EXIT_BOOT_SERVICES event.
163 @retval FALSE The system has not finished executing the EVT_SIGNAL_EXIT_BOOT_SERVICES event.
164
165 **/
166 BOOLEAN
167 EFIAPI
168 EfiAtRuntime (
169 VOID
170 )
171 {
172 return mEfiAtRuntime;
173 }
174
175 /**
176 This function allows the caller to determine if UEFI SetVirtualAddressMap() has been called.
177
178 This function returns TRUE after all the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE functions have
179 executed as a result of the OS calling SetVirtualAddressMap(). Prior to this time FALSE
180 is returned. This function is used by runtime code to decide it is legal to access services
181 that go away after SetVirtualAddressMap().
182
183 @retval TRUE The system has finished executing the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
184 @retval FALSE The system has not finished executing the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
185
186 **/
187 BOOLEAN
188 EFIAPI
189 EfiGoneVirtual (
190 VOID
191 )
192 {
193 return mEfiGoneVirtual;
194 }
195