]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiRuntimeLib/RuntimeLib.c
Remove the work-around in DevicePathLib to judge the end of device path node type.
[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 Initialize 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->CreateEventEx (
98 EVT_NOTIFY_SIGNAL,
99 TPL_NOTIFY,
100 RuntimeLibVirtualNotifyEvent,
101 NULL,
102 &gEfiEventVirtualAddressChangeGuid,
103 &mEfiVirtualNotifyEvent
104 );
105
106 ASSERT_EFI_ERROR (Status);
107
108 Status = gBS->CreateEventEx (
109 EVT_NOTIFY_SIGNAL,
110 TPL_NOTIFY,
111 RuntimeLibExitBootServicesEvent,
112 NULL,
113 &gEfiEventExitBootServicesGuid,
114 &mEfiExitBootServicesEvent
115 );
116
117 ASSERT_EFI_ERROR (Status);
118
119 return Status;
120 }
121
122 /**
123 If a runtime driver exits with an error, it must call this routine
124 to free the allocated resource before the exiting.
125 It will ASSERT() if gBS is NULL.
126 It will ASSERT() if that operation fails.
127
128 @param[in] ImageHandle The firmware allocated handle for the EFI image.
129 @param[in] SystemTable A pointer to the EFI System Table.
130
131 @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully
132 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all
133 **/
134 EFI_STATUS
135 EFIAPI
136 RuntimeDriverLibDeconstruct (
137 IN EFI_HANDLE ImageHandle,
138 IN EFI_SYSTEM_TABLE *SystemTable
139 )
140 {
141 EFI_STATUS Status;
142
143 //
144 // Close SetVirtualAddressMap () notify function
145 //
146 ASSERT (gBS != NULL);
147 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);
148 ASSERT_EFI_ERROR (Status);
149
150 Status = gBS->CloseEvent (mEfiExitBootServicesEvent);
151 ASSERT_EFI_ERROR (Status);
152
153 return Status;
154 }
155
156 /**
157 This function allows the caller to determine if UEFI ExitBootServices() has been called.
158
159 This function returns TRUE after all the EVT_SIGNAL_EXIT_BOOT_SERVICES functions have
160 executed as a result of the OS calling ExitBootServices(). Prior to this time FALSE
161 is returned. This function is used by runtime code to decide it is legal to access
162 services that go away after ExitBootServices().
163
164 @retval TRUE The system has finished executing the EVT_SIGNAL_EXIT_BOOT_SERVICES event.
165 @retval FALSE The system has not finished executing the EVT_SIGNAL_EXIT_BOOT_SERVICES event.
166
167 **/
168 BOOLEAN
169 EFIAPI
170 EfiAtRuntime (
171 VOID
172 )
173 {
174 return mEfiAtRuntime;
175 }
176
177 /**
178 This function allows the caller to determine if UEFI SetVirtualAddressMap() has been called.
179
180 This function returns TRUE after all the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE functions have
181 executed as a result of the OS calling SetVirtualAddressMap(). Prior to this time FALSE
182 is returned. This function is used by runtime code to decide it is legal to access services
183 that go away after SetVirtualAddressMap().
184
185 @retval TRUE The system has finished executing the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
186 @retval FALSE The system has not finished executing the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
187
188 **/
189 BOOLEAN
190 EFIAPI
191 EfiGoneVirtual (
192 VOID
193 )
194 {
195 return mEfiGoneVirtual;
196 }
197