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.
18 Light weight lib to support Tiano drivers.
23 #include <RuntimeLibInternal.h>
26 // Driver Lib Module Globals
29 STATIC EFI_EVENT mRuntimeNotifyEvent
;
30 STATIC EFI_EVENT mEfiVirtualNotifyEvent
;
32 STATIC EFI_PLABEL mPlabel
;
33 STATIC EXTENDED_SAL_BOOT_SERVICE_PROTOCOL
*mEsalBootService
;
35 EFI_RUNTIME_SERVICES
*mRT
= NULL
;
40 RuntimeDriverExitBootServices (
48 Set AtRuntime flag as TRUE after ExitBootServices
52 Event - The Event that is being processed
54 Context - Event Context
62 EFI_EVENT_NOTIFY ChildNotifyEventHandler
;
65 for (Index
= 0; _gDriverExitBootServicesEvent
[Index
] != NULL
; Index
++) {
66 ChildNotifyEventHandler
= _gDriverExitBootServicesEvent
[Index
];
67 ChildNotifyEventHandler (Event
, NULL
);
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
);
112 // Clear out BootService globals
120 RuntimeDriverLibConstruct (
121 IN EFI_HANDLE ImageHandle
,
122 IN EFI_SYSTEM_TABLE
*SystemTable
128 Intialize runtime Driver Lib if it has not yet been initialized.
132 ImageHandle - The firmware allocated handle for the EFI image.
134 SystemTable - A pointer to the EFI System Table.
136 GoVirtualChildEvent - Caller can register a virtual notification event.
140 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.
147 mRT
= SystemTable
->RuntimeServices
;
150 // The protocol contains a function pointer, which is an indirect procedure call.
151 // An indirect procedure call goes through a plabel, and pointer to a function is
152 // a pointer to a plabel. To implement indirect procedure calls that can work in
153 // both physical and virtual mode, two plabels are required (one physical and one
154 // virtual). So lets grap the physical PLABEL for the EsalEntryPoint and store it
155 // away. We cache it in a module global, so we can register the vitrual version.
157 Status
= gBS
->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid
, NULL
, &mEsalBootService
);
158 ASSERT_EFI_ERROR (Status
);
160 Plabel
= (EFI_PLABEL
*) (UINTN
) mEsalBootService
->ExtendedSalProc
;
162 mPlabel
.EntryPoint
= Plabel
->EntryPoint
;
163 mPlabel
.GP
= Plabel
->GP
;
165 SetEsalPhysicalEntryPoint (mPlabel
.EntryPoint
, mPlabel
.GP
);
168 // Register our ExitBootServices () notify function
171 Status
= gBS
->CreateEvent (
172 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES
,
174 RuntimeDriverExitBootServices
,
178 ASSERT_EFI_ERROR (Status
);
181 // Register SetVirtualAddressMap () notify function
184 Status
= gBS
->CreateEvent (
185 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
,
187 RuntimeLibVirtualNotifyEvent
,
189 mEfiVirtualNotifyEvent
191 ASSERT_EFI_ERROR (Status
);
197 RuntimeDriverLibDeconstruct (
204 This routine will free some resources which have been allocated in
205 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,
206 it must call this routine to free the allocated resource before the exiting.
214 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully
215 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all
222 // Close our ExitBootServices () notify function
224 Status
= gBS
->CloseEvent (mRuntimeNotifyEvent
);
225 ASSERT_EFI_ERROR (Status
);
228 // Close SetVirtualAddressMap () notify function
230 Status
= gBS
->CloseEvent (mEfiVirtualNotifyEvent
);
231 ASSERT_EFI_ERROR (Status
);
243 Return TRUE if ExitBootService () has been called
249 TRUE - If ExitBootService () has been called
253 EFI_GUID Guid
= EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID
;
254 SAL_RETURN_REGS ReturnReg
;
256 ReturnReg
= EfiCallEsalService (&Guid
, IsEfiRuntime
, 0, 0, 0, 0, 0, 0, 0);
258 return (BOOLEAN
) (ReturnReg
.r9
== 1);
268 Return TRUE if SetVirtualAddressMap () has been called
274 TRUE - If SetVirtualAddressMap () has been called
278 EFI_GUID Guid
= EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID
;
279 SAL_RETURN_REGS ReturnReg
;
281 ReturnReg
= EfiCallEsalService (&Guid
, IsVirtual
, 0, 0, 0, 0, 0, 0, 0);
283 return (BOOLEAN
) (ReturnReg
.r9
== 1);