Home | History | Annotate | Download | only in DxeCoreReportStatusCodeLibFromHob
      1 /** @file
      2   Report Status Code Library that depends on a GUIDed HOB for report status
      3   code functionality.
      4 
      5   Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
      6   This program and the accompanying materials
      7   are licensed and made available under the terms and conditions of the BSD License
      8   which accompanies this distribution.  The full text of the license may be found at
      9   http://opensource.org/licenses/bsd-license.php
     10 
     11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 
     16 #include "ReportStatusCodeLibInternal.h"
     17 
     18 //
     19 // Handle to install report status code protocol interface
     20 //
     21 EFI_HANDLE               mHandle = NULL;
     22 
     23 //
     24 // Report status protocol interface.
     25 //
     26 EFI_STATUS_CODE_PROTOCOL mStatusProtocol = {
     27   NULL
     28 };
     29 
     30 /**
     31   Initializes report status code infrastructure for DXE phase.
     32 
     33   The constructor function assumes the PEI phase has published the GUIDed HOB
     34   tagged by gEfiStatusCodeRuntimeProtocolGuid and publish status code runtime
     35   protocol based on the GUID data. It will ASSERT() if one of these operations
     36   fails and it will always return EFI_SUCCESS.
     37 
     38   @param  ImageHandle   The firmware allocated handle for the EFI image.
     39   @param  SystemTable   A pointer to the EFI System Table.
     40 
     41   @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.
     42 
     43 **/
     44 EFI_STATUS
     45 EFIAPI
     46 DxeCoreReportStatusCodeFromHobLibConstructor (
     47   IN EFI_HANDLE        ImageHandle,
     48   IN EFI_SYSTEM_TABLE  *SystemTable
     49   )
     50 {
     51   EFI_STATUS           Status;
     52   EFI_HOB_GUID_TYPE    *GuidHob;
     53 
     54   GuidHob = GetFirstGuidHob(&gEfiStatusCodeRuntimeProtocolGuid);
     55   ASSERT (GuidHob != NULL);
     56 
     57   mStatusProtocol.ReportStatusCode = (EFI_REPORT_STATUS_CODE) (*(UINTN *) GET_GUID_HOB_DATA (GuidHob));
     58   ASSERT (mStatusProtocol.ReportStatusCode != NULL);
     59 
     60   //
     61   // Install report status protocol interface so that later DXE phase drivers can retrieve the protocol
     62   // interface to report status code.
     63   //
     64   Status = gBS->InstallProtocolInterface (
     65                   &mHandle,
     66                   &gEfiStatusCodeRuntimeProtocolGuid,
     67                   EFI_NATIVE_INTERFACE,
     68                   &mStatusProtocol
     69                   );
     70   ASSERT_EFI_ERROR (Status);
     71 
     72   return Status;
     73 }
     74 
     75 /**
     76   Reports a status code with full parameters.
     77 
     78   The function reports a status code.  If ExtendedData is NULL and ExtendedDataSize
     79   is 0, then an extended data buffer is not reported.  If ExtendedData is not
     80   NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
     81   ExtendedData is assumed not have the standard status code header, so this function
     82   is responsible for allocating a buffer large enough for the standard header and
     83   the extended data passed into this function.  The standard header is filled in
     84   with a GUID specified by ExtendedDataGuid.  If ExtendedDataGuid is NULL, then a
     85   GUID of gEfiStatusCodeSpecificDatauid is used.  The status code is reported with
     86   an instance specified by Instance and a caller ID specified by CallerId.  If
     87   CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
     88 
     89   ReportStatusCodeEx()must actively prevent recursion.  If ReportStatusCodeEx()
     90   is called while processing another any other Report Status Code Library function,
     91   then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
     92 
     93   If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
     94   If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
     95 
     96   @param  Type              Status code type.
     97   @param  Value             Status code value.
     98   @param  Instance          Status code instance number.
     99   @param  CallerId          Pointer to a GUID that identifies the caller of this
    100                             function.  If this parameter is NULL, then a caller
    101                             ID of gEfiCallerIdGuid is used.
    102   @param  ExtendedDataGuid  Pointer to the GUID for the extended data buffer.
    103                             If this parameter is NULL, then a the status code
    104                             standard header is filled in with
    105                             gEfiStatusCodeSpecificDataGuid.
    106   @param  ExtendedData      Pointer to the extended data buffer.  This is an
    107                             optional parameter that may be NULL.
    108   @param  ExtendedDataSize  The size, in bytes, of the extended data buffer.
    109 
    110   @retval  EFI_SUCCESS           The status code was reported.
    111   @retval  EFI_OUT_OF_RESOURCES  There were not enough resources to allocate
    112                                  the extended data section if it was specified.
    113   @retval  EFI_UNSUPPORTED       Report status code is not supported
    114 
    115 **/
    116 EFI_STATUS
    117 EFIAPI
    118 InternalReportStatusCodeEx (
    119   IN EFI_STATUS_CODE_TYPE   Type,
    120   IN EFI_STATUS_CODE_VALUE  Value,
    121   IN UINT32                 Instance,
    122   IN CONST EFI_GUID         *CallerId          OPTIONAL,
    123   IN CONST EFI_GUID         *ExtendedDataGuid  OPTIONAL,
    124   IN CONST VOID             *ExtendedData      OPTIONAL,
    125   IN UINTN                  ExtendedDataSize
    126   )
    127 {
    128   EFI_STATUS            Status;
    129   EFI_STATUS_CODE_DATA  *StatusCodeData;
    130 
    131   ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
    132   ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
    133 
    134   if (gBS == NULL) {
    135     return EFI_UNSUPPORTED;
    136   }
    137 
    138   //
    139   // Allocate space for the Status Code Header and its buffer
    140   //
    141   StatusCodeData = NULL;
    142   gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);
    143   if (StatusCodeData == NULL) {
    144     return EFI_OUT_OF_RESOURCES;
    145   }
    146 
    147   //
    148   // Fill in the extended data header
    149   //
    150   StatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);
    151   StatusCodeData->Size = (UINT16)ExtendedDataSize;
    152   if (ExtendedDataGuid == NULL) {
    153     ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;
    154   }
    155   CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);
    156 
    157   //
    158   // Fill in the extended data buffer
    159   //
    160   CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);
    161 
    162   //
    163   // Report the status code
    164   //
    165   if (CallerId == NULL) {
    166     CallerId = &gEfiCallerIdGuid;
    167   }
    168   Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);
    169 
    170   //
    171   // Free the allocated buffer
    172   //
    173   gBS->FreePool (StatusCodeData);
    174 
    175   return Status;
    176 }
    177 
    178