RuntimeLib.c revision 42eedea958591087603bbacd1c2227d2494026af
1/** @file 2 Library utility functions for Runtime driver. 3 4Copyright (c) 2006 Intel Corporation. <BR> 5All rights reserved. This program and the accompanying materials 6are licensed and made available under the terms and conditions of the BSD License 7which accompanies this distribution. The full text of the license may be found at 8http://opensource.org/licenses/bsd-license.php 9 10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11WITHOUT 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 21STATIC EFI_EVENT mEfiVirtualNotifyEvent; 22STATIC EFI_EVENT mEfiExitBootServicesEvent; 23STATIC BOOLEAN mEfiGoneVirtual = FALSE; 24STATIC BOOLEAN mEfiAtRuntime = FALSE; 25EFI_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**/ 33VOID 34EFIAPI 35RuntimeLibExitBootServicesEvent ( 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**/ 56VOID 57EFIAPI 58RuntimeLibVirtualNotifyEvent ( 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 74 @param[in] ImageHandle The firmware allocated handle for the EFI image. 75 @param[in] SystemTable A pointer to the EFI System Table. 76 77 @return EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started. 78**/ 79EFI_STATUS 80EFIAPI 81RuntimeDriverLibConstruct ( 82 IN EFI_HANDLE ImageHandle, 83 IN EFI_SYSTEM_TABLE *SystemTable 84 ) 85{ 86 EFI_STATUS Status; 87 88 mRT = gRT; 89 ASSERT (mRT != NULL); 90 91 // 92 // Register SetVirtualAddressMap () notify function 93 // 94 ASSERT (gBS != NULL); 95 Status = gBS->CreateEvent ( 96 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE, 97 TPL_NOTIFY, 98 RuntimeLibVirtualNotifyEvent, 99 NULL, 100 &mEfiVirtualNotifyEvent 101 ); 102 103 ASSERT_EFI_ERROR (Status); 104 105 Status = gBS->CreateEvent ( 106 EVT_SIGNAL_EXIT_BOOT_SERVICES, 107 TPL_NOTIFY, 108 RuntimeLibExitBootServicesEvent, 109 NULL, 110 &mEfiExitBootServicesEvent 111 ); 112 113 ASSERT_EFI_ERROR (Status); 114 115 return Status; 116} 117 118/** 119 This routine will free some resources which have been allocated in 120 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, 121 it must call this routine to free the allocated resource before the exiting. 122 123 @param[in] ImageHandle The firmware allocated handle for the EFI image. 124 @param[in] SystemTable A pointer to the EFI System Table. 125 126 @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully 127 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all 128**/ 129EFI_STATUS 130EFIAPI 131RuntimeDriverLibDeconstruct ( 132 IN EFI_HANDLE ImageHandle, 133 IN EFI_SYSTEM_TABLE *SystemTable 134 ) 135{ 136 EFI_STATUS Status; 137 138 // 139 // Close SetVirtualAddressMap () notify function 140 // 141 ASSERT (gBS != NULL); 142 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent); 143 ASSERT_EFI_ERROR (Status); 144 145 Status = gBS->CloseEvent (mEfiExitBootServicesEvent); 146 ASSERT_EFI_ERROR (Status); 147 148 return Status; 149} 150 151/** 152 Return TRUE if ExitBootServices () has been called. 153 154 @retval TRUE If ExitBootServices () has been called 155**/ 156BOOLEAN 157EFIAPI 158EfiAtRuntime ( 159 VOID 160 ) 161{ 162 return mEfiAtRuntime; 163} 164 165/** 166 Return TRUE if SetVirtualAddressMap () has been called. 167 168 @retval TRUE If SetVirtualAddressMap () has been called 169**/ 170BOOLEAN 171EFIAPI 172EfiGoneVirtual ( 173 VOID 174 ) 175{ 176 return mEfiGoneVirtual; 177} 178 179