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
121 RuntimeDriverLibConstruct (
122 IN EFI_HANDLE ImageHandle
,
123 IN EFI_SYSTEM_TABLE
*SystemTable
129 Intialize runtime Driver Lib if it has not yet been initialized.
133 ImageHandle - The firmware allocated handle for the EFI image.
135 SystemTable - A pointer to the EFI System Table.
137 GoVirtualChildEvent - Caller can register a virtual notification event.
141 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.
148 mRT
= SystemTable
->RuntimeServices
;
151 // The protocol contains a function pointer, which is an indirect procedure call.
152 // An indirect procedure call goes through a plabel, and pointer to a function is
153 // a pointer to a plabel. To implement indirect procedure calls that can work in
154 // both physical and virtual mode, two plabels are required (one physical and one
155 // virtual). So lets grap the physical PLABEL for the EsalEntryPoint and store it
156 // away. We cache it in a module global, so we can register the vitrual version.
158 Status
= gBS
->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid
, NULL
, &mEsalBootService
);
159 ASSERT_EFI_ERROR (Status
);
161 Plabel
= (EFI_PLABEL
*) (UINTN
) mEsalBootService
->ExtendedSalProc
;
163 mPlabel
.EntryPoint
= Plabel
->EntryPoint
;
164 mPlabel
.GP
= Plabel
->GP
;
166 SetEsalPhysicalEntryPoint (mPlabel
.EntryPoint
, mPlabel
.GP
);
169 // Register our ExitBootServices () notify function
172 Status
= gBS
->CreateEvent (
173 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES
,
175 RuntimeDriverExitBootServices
,
179 ASSERT_EFI_ERROR (Status
);
182 // Register SetVirtualAddressMap () notify function
185 Status
= gBS
->CreateEvent (
186 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
,
188 RuntimeLibVirtualNotifyEvent
,
190 mEfiVirtualNotifyEvent
192 ASSERT_EFI_ERROR (Status
);
199 RuntimeDriverLibDeconstruct (
206 This routine will free some resources which have been allocated in
207 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,
208 it must call this routine to free the allocated resource before the exiting.
216 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully
217 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all
224 // Close our ExitBootServices () notify function
226 Status
= gBS
->CloseEvent (mRuntimeNotifyEvent
);
227 ASSERT_EFI_ERROR (Status
);
230 // Close SetVirtualAddressMap () notify function
232 Status
= gBS
->CloseEvent (mEfiVirtualNotifyEvent
);
233 ASSERT_EFI_ERROR (Status
);
245 Return TRUE if ExitBootService () has been called
251 TRUE - If ExitBootService () has been called
255 EFI_GUID Guid
= EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID
;
256 SAL_RETURN_REGS ReturnReg
;
258 ReturnReg
= EfiCallEsalService (&Guid
, IsEfiRuntime
, 0, 0, 0, 0, 0, 0, 0);
260 return (BOOLEAN
) (ReturnReg
.r9
== 1);
270 Return TRUE if SetVirtualAddressMap () has been called
276 TRUE - If SetVirtualAddressMap () has been called
280 EFI_GUID Guid
= EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID
;
281 SAL_RETURN_REGS ReturnReg
;
283 ReturnReg
= EfiCallEsalService (&Guid
, IsVirtual
, 0, 0, 0, 0, 0, 0, 0);
285 return (BOOLEAN
) (ReturnReg
.r9
== 1);