RuntimeLib.c revision 21998b6778c9b77085330c4711f4cc55aa7c1e41
1ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang/**@file 2ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang Library utility functions for Runtime driver. 3ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 4ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangCopyright (c) 2006 Intel Corporation. <BR> 5ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangAll rights reserved. This program and the accompanying materials 6ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangare licensed and made available under the terms and conditions of the BSD License 7ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangwhich accompanies this distribution. The full text of the license may be found at 8ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshanghttp://opensource.org/licenses/bsd-license.php 9ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 10ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangTHE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangWITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 13ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang**/ 14ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 15ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang#include <RuntimeLibInternal.h> 16ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 17ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang/// 18ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang/// Driver Lib Module Globals 19ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang/// 20ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 21ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangSTATIC EFI_EVENT mEfiVirtualNotifyEvent; 2221998b6778c9b77085330c4711f4cc55aa7c1e41yshangSTATIC EFI_EVENT mEfiExitBootServicesEvent; 23ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangSTATIC BOOLEAN mEfiGoneVirtual = FALSE; 24ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangSTATIC BOOLEAN mEfiAtRuntime = FALSE; 25ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangEFI_RUNTIME_SERVICES *mRT; 26ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 27ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang/** 28ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang Set AtRuntime flag as TRUE after ExitBootServices 29ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 30ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang @param[in] Event The Event that is being processed 31ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang @param[in] Context Event Context 32ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang**/ 3321998b6778c9b77085330c4711f4cc55aa7c1e41yshangSTATIC 34ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangVOID 35ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangEFIAPI 3621998b6778c9b77085330c4711f4cc55aa7c1e41yshangRuntimeLibExitBootServicesEvent ( 37ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang IN EFI_EVENT Event, 38ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang IN VOID *Context 39ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ) 40ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang{ 41ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang // 42ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang // Clear out BootService globals 43ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang // 44ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang gBS = NULL; 45ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 46ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang mEfiAtRuntime = TRUE; 47ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang} 48ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 49ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang/** 50ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang Fixup internal data so that EFI can be call in virtual mode. 51ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang Call the passed in Child Notify event and convert any pointers in 52ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang lib to virtual mode. 53ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 54ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang @param[in] Event The Event that is being processed 55ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang @param[in] Context Event Context 56ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang**/ 57ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangSTATIC 58ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangVOID 59ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangEFIAPI 60ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangRuntimeLibVirtualNotifyEvent ( 61ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang IN EFI_EVENT Event, 62ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang IN VOID *Context 63ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ) 64ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang{ 65ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang // 66ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang // Update global for Runtime Services Table and IO 67ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang // 68ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang EfiConvertPointer (0, (VOID **) &mRT); 69ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 70ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang mEfiGoneVirtual = TRUE; 71ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang} 72ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 73ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang/** 74ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang Intialize runtime Driver Lib if it has not yet been initialized. 75ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 76ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang @param[in] ImageHandle The firmware allocated handle for the EFI image. 77ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang @param[in] SystemTable A pointer to the EFI System Table. 78ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 79ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang @return EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started. 80ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang**/ 81ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangEFI_STATUS 82ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangEFIAPI 83ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangRuntimeDriverLibConstruct ( 84ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang IN EFI_HANDLE ImageHandle, 85ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang IN EFI_SYSTEM_TABLE *SystemTable 86ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ) 87ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang{ 88ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang EFI_STATUS Status; 89ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 90ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ASSERT (SystemTable != NULL); 91ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang mRT = SystemTable->RuntimeServices; 92ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ASSERT (mRT != NULL); 93ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 94ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang // 95ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang // Register SetVirtualAddressMap () notify function 96ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang // 97ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ASSERT (gBS != NULL); 98ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang Status = gBS->CreateEvent ( 99ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE, 100ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang TPL_NOTIFY, 101ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang RuntimeLibVirtualNotifyEvent, 102ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang NULL, 103ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang &mEfiVirtualNotifyEvent 104ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ); 105ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 106ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ASSERT_EFI_ERROR (Status); 107ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 10821998b6778c9b77085330c4711f4cc55aa7c1e41yshang Status = gBS->CreateEvent ( 10921998b6778c9b77085330c4711f4cc55aa7c1e41yshang EVT_SIGNAL_EXIT_BOOT_SERVICES, 11021998b6778c9b77085330c4711f4cc55aa7c1e41yshang TPL_NOTIFY, 11121998b6778c9b77085330c4711f4cc55aa7c1e41yshang RuntimeLibExitBootServicesEvent, 11221998b6778c9b77085330c4711f4cc55aa7c1e41yshang NULL, 11321998b6778c9b77085330c4711f4cc55aa7c1e41yshang &mEfiExitBootServicesEvent 11421998b6778c9b77085330c4711f4cc55aa7c1e41yshang ); 11521998b6778c9b77085330c4711f4cc55aa7c1e41yshang 11621998b6778c9b77085330c4711f4cc55aa7c1e41yshang ASSERT_EFI_ERROR (Status); 11721998b6778c9b77085330c4711f4cc55aa7c1e41yshang 118ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang return Status; 119ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang} 120ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 121ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang/** 122ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang This routine will free some resources which have been allocated in 123ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, 124ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang it must call this routine to free the allocated resource before the exiting. 125ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 126ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully 127ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all 128ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang**/ 129ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangEFI_STATUS 130ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangEFIAPI 131ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangRuntimeDriverLibDeconstruct ( 132ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang IN EFI_HANDLE ImageHandle, 133ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang IN EFI_SYSTEM_TABLE *SystemTable 134ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ) 135ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang{ 136ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang EFI_STATUS Status; 137ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 138ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang // 139ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang // Close SetVirtualAddressMap () notify function 140ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang // 141ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ASSERT (gBS != NULL); 142ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang Status = gBS->CloseEvent (mEfiVirtualNotifyEvent); 143ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ASSERT_EFI_ERROR (Status); 144ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 14521998b6778c9b77085330c4711f4cc55aa7c1e41yshang Status = gBS->CloseEvent (mEfiExitBootServicesEvent); 14621998b6778c9b77085330c4711f4cc55aa7c1e41yshang ASSERT_EFI_ERROR (Status); 14721998b6778c9b77085330c4711f4cc55aa7c1e41yshang 148ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang return Status; 149ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang} 150ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 151ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang/** 152ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang Return TRUE if ExitBootServices () has been called 153ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 154ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang @retval TRUE If ExitBootServices () has been called 155ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang**/ 156ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangBOOLEAN 157ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangEFIAPI 158ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangEfiAtRuntime ( 159ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang VOID 160ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ) 161ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang{ 162ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang return mEfiAtRuntime; 163ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang} 164ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 165ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang/** 166ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang Return TRUE if SetVirtualAddressMap () has been called 167ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 168ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang @retval TRUE If SetVirtualAddressMap () has been called 169ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang**/ 170ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangBOOLEAN 171ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangEFIAPI 172ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshangEfiGoneVirtual ( 173ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang VOID 174ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang ) 175ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang{ 176ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang return mEfiGoneVirtual; 177ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang} 178ebcc8fb7ba239020d307ce113fb30ae120b6fcafyshang 179