Home | History | Annotate | Download | only in Ebc
      1 /*++
      2 
      3 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
      4 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
      8 
      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.
     11 
     12 Module Name:
     13 
     14     RuntimeLib.c
     15 
     16 Abstract:
     17 
     18   Light weight lib to support Tiano drivers.
     19 
     20 --*/
     21 
     22 #include "Tiano.h"
     23 #include "EfiRuntimeLib.h"
     24 #include EFI_GUID_DEFINITION (StatusCodeCallerId)
     25 #include EFI_ARCH_PROTOCOL_DEFINITION (StatusCode)
     26 
     27 //
     28 // Driver Lib Module Globals
     29 //
     30 static EFI_RUNTIME_SERVICES *mRT;
     31 static EFI_EVENT            mRuntimeNotifyEvent     = NULL;
     32 static BOOLEAN              mRuntimeLibInitialized  = FALSE;
     33 static BOOLEAN              mEfiGoneVirtual         = FALSE;
     34 
     35 //
     36 // Runtime Global, but you should use the Lib functions
     37 //
     38 BOOLEAN                     mEfiAtRuntime = FALSE;
     39 
     40 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
     41 static EFI_STATUS_CODE_PROTOCOL  *gStatusCode = NULL;
     42 #endif
     43 
     44 EFI_STATUS
     45 EfiConvertPointer (
     46   IN UINTN                     DebugDisposition,
     47   IN OUT VOID                  *Address
     48   )
     49 /*++
     50 
     51 Routine Description:
     52 
     53   Determines the new virtual address that is to be used on subsequent memory accesses.
     54 
     55 Arguments:
     56 
     57   DebugDisposition  - Supplies type information for the pointer being converted.
     58   Address           - A pointer to a pointer that is to be fixed to be the value needed
     59                       for the new virtual address mappings being applied.
     60 
     61 Returns:
     62 
     63   Status code
     64 
     65 --*/
     66 {
     67   return mRT->ConvertPointer (DebugDisposition, Address);
     68 }
     69 
     70 VOID
     71 EFIAPI
     72 RuntimeDriverExitBootServices (
     73   IN EFI_EVENT        Event,
     74   IN VOID             *Context
     75   )
     76 /*++
     77 
     78 Routine Description:
     79 
     80   Set AtRuntime flag as TRUE after ExitBootServices
     81 
     82 Arguments:
     83 
     84   Event   - The Event that is being processed
     85 
     86   Context - Event Context
     87 
     88 Returns:
     89 
     90   None
     91 
     92 --*/
     93 {
     94   mEfiAtRuntime = TRUE;
     95 }
     96 
     97 EFI_STATUS
     98 EfiInitializeRuntimeDriverLib (
     99   IN EFI_HANDLE           ImageHandle,
    100   IN EFI_SYSTEM_TABLE     *SystemTable,
    101   IN EFI_EVENT_NOTIFY     GoVirtualChildEvent
    102   )
    103 /*++
    104 
    105 Routine Description:
    106 
    107   Intialize runtime Driver Lib if it has not yet been initialized.
    108 
    109 Arguments:
    110 
    111   ImageHandle     - The firmware allocated handle for the EFI image.
    112 
    113   SystemTable     - A pointer to the EFI System Table.
    114 
    115   GoVirtualChildEvent - Caller can register a virtual notification event.
    116 
    117 Returns:
    118 
    119   EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.
    120 
    121 --*/
    122 {
    123   EFI_STATUS  Status;
    124 
    125   if (mRuntimeLibInitialized) {
    126     return EFI_ALREADY_STARTED;
    127   }
    128 
    129   mRuntimeLibInitialized  = TRUE;
    130 
    131   gST = SystemTable;
    132   ASSERT (gST != NULL);
    133 
    134   gBS = SystemTable->BootServices;
    135   ASSERT (gBS != NULL);
    136   mRT = SystemTable->RuntimeServices;
    137   ASSERT (mRT != NULL);
    138 
    139   Status  = EfiLibGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);
    140   ASSERT_EFI_ERROR (Status);
    141 
    142 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
    143   Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);
    144   if (EFI_ERROR (Status)) {
    145     gStatusCode = NULL;
    146   }
    147 #endif
    148 
    149   //
    150   // Register our ExitBootServices () notify function
    151   //
    152   Status = gBS->CreateEvent (
    153                   EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,
    154                   EFI_TPL_NOTIFY,
    155                   RuntimeDriverExitBootServices,
    156                   NULL,
    157                   &mRuntimeNotifyEvent
    158                   );
    159   ASSERT_EFI_ERROR (Status);
    160 
    161   //
    162   // To NOT register SetVirtualAddressMap () notify function,
    163   // because we do not know how to trigger it without our EBC driver.
    164   //
    165 
    166   return EFI_SUCCESS;
    167 }
    168 
    169 EFI_STATUS
    170 EfiShutdownRuntimeDriverLib (
    171   VOID
    172   )
    173 /*++
    174 
    175 Routine Description:
    176 
    177   This routine will free some resources which have been allocated in
    178   EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,
    179   it must call this routine to free the allocated resource before the exiting.
    180 
    181 Arguments:
    182 
    183   None
    184 
    185 Returns:
    186 
    187   EFI_SUCCESS     - Shotdown the Runtime Driver Lib successfully
    188   EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all
    189 
    190 --*/
    191 {
    192   EFI_STATUS  Status;
    193 
    194   if (!mRuntimeLibInitialized) {
    195     //
    196     // You must call EfiInitializeRuntimeDriverLib() first
    197     //
    198     return EFI_UNSUPPORTED;
    199   }
    200 
    201   mRuntimeLibInitialized = FALSE;
    202 
    203   //
    204   // Close our ExitBootServices () notify function
    205   //
    206   if (mRuntimeNotifyEvent != NULL) {
    207     Status = gBS->CloseEvent (mRuntimeNotifyEvent);
    208     ASSERT_EFI_ERROR (Status);
    209   }
    210 
    211   return EFI_SUCCESS;
    212 }
    213 
    214 BOOLEAN
    215 EfiAtRuntime (
    216   VOID
    217   )
    218 /*++
    219 
    220 Routine Description:
    221   Return TRUE if ExitBootServices () has been called
    222 
    223 Arguments:
    224   NONE
    225 
    226 Returns:
    227   TRUE - If ExitBootServices () has been called
    228 
    229 --*/
    230 {
    231   return mEfiAtRuntime;
    232 }
    233 
    234 BOOLEAN
    235 EfiGoneVirtual (
    236   VOID
    237   )
    238 /*++
    239 
    240 Routine Description:
    241   Return TRUE if SetVirtualAddressMap () has been called
    242 
    243 Arguments:
    244   NONE
    245 
    246 Returns:
    247   TRUE - If SetVirtualAddressMap () has been called
    248 
    249 --*/
    250 {
    251   return mEfiGoneVirtual;
    252 }
    253 
    254 EFI_STATUS
    255 EfiReportStatusCode (
    256   IN EFI_STATUS_CODE_TYPE     CodeType,
    257   IN EFI_STATUS_CODE_VALUE    Value,
    258   IN UINT32                   Instance,
    259   IN EFI_GUID                 * CallerId,
    260   IN EFI_STATUS_CODE_DATA     * Data OPTIONAL
    261   )
    262 /*++
    263 
    264 Routine Description:
    265 
    266   Status Code reporter
    267 
    268 Arguments:
    269 
    270   CodeType    - Type of Status Code.
    271 
    272   Value       - Value to output for Status Code.
    273 
    274   Instance    - Instance Number of this status code.
    275 
    276   CallerId    - ID of the caller of this status code.
    277 
    278   Data        - Optional data associated with this status code.
    279 
    280 Returns:
    281 
    282   Status code
    283 
    284 --*/
    285 {
    286   return EFI_UNSUPPORTED;
    287 }
    288 //
    289 // Cache Flush Routine.
    290 //
    291 EFI_STATUS
    292 EfiCpuFlushCache (
    293   IN EFI_PHYSICAL_ADDRESS          Start,
    294   IN UINT64                        Length
    295   )
    296 /*++
    297 
    298 Routine Description:
    299 
    300   Flush cache with specified range.
    301 
    302 Arguments:
    303 
    304   Start   - Start address
    305   Length  - Length in bytes
    306 
    307 Returns:
    308 
    309   Status code
    310 
    311   EFI_SUCCESS - success
    312 
    313 --*/
    314 {
    315   return EFI_SUCCESS;
    316 }
    317