3 Copyright (c) 2006, 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
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.
19 #include <RuntimeLibInternal.h>
22 // Driver Lib Module Globals
25 STATIC EFI_EVENT mRuntimeNotifyEvent
;
26 STATIC EFI_EVENT mEfiVirtualNotifyEvent
;
27 STATIC EFI_PLABEL mPlabel
;
28 STATIC EXTENDED_SAL_BOOT_SERVICE_PROTOCOL
*mEsalBootService
;
30 EFI_RUNTIME_SERVICES
*mRT
;
35 RuntimeDriverExitBootServices (
43 Set AtRuntime flag as TRUE after ExitBootServices
47 Event - The Event that is being processed
49 Context - Event Context
57 EFI_EVENT_NOTIFY ChildNotifyEventHandler
;
60 for (Index
= 0; _gDriverExitBootServicesEvent
[Index
] != NULL
; Index
++) {
61 ChildNotifyEventHandler
= _gDriverExitBootServicesEvent
[Index
];
62 ChildNotifyEventHandler (Event
, NULL
);
66 // Clear out BootService globals
74 RuntimeLibVirtualNotifyEvent (
82 Fixup internal data so that EFI can be call in virtual mode.
83 Call the passed in Child Notify event and convert any pointers in
88 Event - The Event that is being processed
90 Context - Event Context
99 EFI_EVENT_NOTIFY ChildNotifyEventHandler
;
101 for (Index
= 0; _gDriverSetVirtualAddressMapEvent
[Index
] != NULL
; Index
++) {
102 ChildNotifyEventHandler
= _gDriverSetVirtualAddressMapEvent
[Index
];
103 ChildNotifyEventHandler (Event
, NULL
);
106 mRT
->ConvertPointer (0x0, (VOID
**) &mPlabel
.EntryPoint
);
107 mRT
->ConvertPointer (EFI_IPF_GP_POINTER
, (VOID
**) &mPlabel
.GP
);
109 SetEsalVirtualEntryPoint (mPlabel
.EntryPoint
, mPlabel
.GP
);
114 RuntimeDriverLibConstruct (
115 IN EFI_HANDLE ImageHandle
,
116 IN EFI_SYSTEM_TABLE
*SystemTable
122 Intialize runtime Driver Lib if it has not yet been initialized.
126 ImageHandle - The firmware allocated handle for the EFI image.
128 SystemTable - A pointer to the EFI System Table.
130 GoVirtualChildEvent - Caller can register a virtual notification event.
134 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.
141 mRT
= SystemTable
->RuntimeServices
;
144 // The protocol contains a function pointer, which is an indirect procedure call.
145 // An indirect procedure call goes through a plabel, and pointer to a function is
146 // a pointer to a plabel. To implement indirect procedure calls that can work in
147 // both physical and virtual mode, two plabels are required (one physical and one
148 // virtual). So lets grap the physical PLABEL for the EsalEntryPoint and store it
149 // away. We cache it in a module global, so we can register the vitrual version.
151 Status
= gBS
->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid
, NULL
, &mEsalBootService
);
152 ASSERT_EFI_ERROR (Status
);
154 Plabel
= (EFI_PLABEL
*) (UINTN
) mEsalBootService
->ExtendedSalProc
;
156 mPlabel
.EntryPoint
= Plabel
->EntryPoint
;
157 mPlabel
.GP
= Plabel
->GP
;
159 SetEsalPhysicalEntryPoint (mPlabel
.EntryPoint
, mPlabel
.GP
);
162 // Register our ExitBootServices () notify function
165 Status
= gBS
->CreateEvent (
166 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES
,
168 RuntimeDriverExitBootServices
,
172 ASSERT_EFI_ERROR (Status
);
175 // Register SetVirtualAddressMap () notify function
178 Status
= gBS
->CreateEvent (
179 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
,
181 RuntimeLibVirtualNotifyEvent
,
183 mEfiVirtualNotifyEvent
185 ASSERT_EFI_ERROR (Status
);
192 RuntimeDriverLibDeconstruct (
199 This routine will free some resources which have been allocated in
200 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,
201 it must call this routine to free the allocated resource before the exiting.
209 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully
210 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all
217 // Close our ExitBootServices () notify function
219 Status
= gBS
->CloseEvent (mRuntimeNotifyEvent
);
220 ASSERT_EFI_ERROR (Status
);
223 // Close SetVirtualAddressMap () notify function
225 Status
= gBS
->CloseEvent (mEfiVirtualNotifyEvent
);
226 ASSERT_EFI_ERROR (Status
);
239 Return TRUE if ExitBootService () has been called
245 TRUE - If ExitBootService () has been called
249 EFI_GUID Guid
= EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID
;
250 SAL_RETURN_REGS ReturnReg
;
252 ReturnReg
= EfiCallEsalService (&Guid
, IsEfiRuntime
, 0, 0, 0, 0, 0, 0, 0);
254 return (BOOLEAN
) (ReturnReg
.r9
== 1);
265 Return TRUE if SetVirtualAddressMap () has been called
271 TRUE - If SetVirtualAddressMap () has been called
275 EFI_GUID Guid
= EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID
;
276 SAL_RETURN_REGS ReturnReg
;
278 ReturnReg
= EfiCallEsalService (&Guid
, IsVirtual
, 0, 0, 0, 0, 0, 0, 0);
280 return (BOOLEAN
) (ReturnReg
.r9
== 1);