125126a0530371f7a8e20bf663cc1beaf3eebd6f2xli/** @file
225126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  Internal include file for Report Status Code Router Driver.
325126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
4e5eed7d3641d71d7ea539e5379ea9c6a5cd97004hhtian  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
5e5eed7d3641d71d7ea539e5379ea9c6a5cd97004hhtian  This program and the accompanying materials
625126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  are licensed and made available under the terms and conditions of the BSD License
725126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  which accompanies this distribution.  The full text of the license may be found at
825126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  http://opensource.org/licenses/bsd-license.php
925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
1025126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
1125126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
1225126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
1325126a0530371f7a8e20bf663cc1beaf3eebd6f2xli**/
1425126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
1525126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#ifndef __REPORT_STATUS_CODE_ROUTER_RUNTIME_DXE_H__
1625126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#define __REPORT_STATUS_CODE_ROUTER_RUNTIME_DXE_H__
1725126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
1825126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
1925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#include <Protocol/ReportStatusCodeHandler.h>
2025126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#include <Protocol/StatusCode.h>
2125126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
2225126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#include <Guid/EventGroup.h>
2325126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
2425126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#include <Library/BaseLib.h>
2525126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#include <Library/SynchronizationLib.h>
2625126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#include <Library/DebugLib.h>
2725126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#include <Library/HobLib.h>
2825126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#include <Library/UefiDriverEntryPoint.h>
2925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#include <Library/UefiBootServicesTableLib.h>
3025126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#include <Library/MemoryAllocationLib.h>
31cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli#include <Library/BaseMemoryLib.h>
3225126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#include <Library/UefiRuntimeLib.h>
33cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli#include "Library/UefiLib.h"
3425126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
3525126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#define RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE  SIGNATURE_32 ('r', 'h', 'c', 'e')
3625126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
3725126a0530371f7a8e20bf663cc1beaf3eebd6f2xlitypedef struct {
3825126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  UINTN                     Signature;
3925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  EFI_RSC_HANDLER_CALLBACK  RscHandlerCallback;
4025126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  EFI_TPL                   Tpl;
41cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli  EFI_EVENT                 Event;
42cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli  EFI_PHYSICAL_ADDRESS      StatusCodeDataBuffer;
43cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli  UINTN                     BufferSize;
44cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli  EFI_PHYSICAL_ADDRESS      EndPointer;
4525126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  LIST_ENTRY                Node;
4625126a0530371f7a8e20bf663cc1beaf3eebd6f2xli} RSC_HANDLER_CALLBACK_ENTRY;
4725126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
4825126a0530371f7a8e20bf663cc1beaf3eebd6f2xlitypedef struct {
49cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli  EFI_STATUS_CODE_TYPE      Type;
50cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli  EFI_STATUS_CODE_VALUE     Value;
51cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli  UINT32                    Instance;
52cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli  UINT32                    Reserved;
53cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli  EFI_GUID                  CallerId;
54cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli  EFI_STATUS_CODE_DATA      Data;
55cfc2ba61e499764a7cfbfef4da37f95bd54c2987xli} RSC_DATA_ENTRY;
5625126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
5725126a0530371f7a8e20bf663cc1beaf3eebd6f2xli/**
5825126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  Register the callback function for ReportStatusCode() notification.
5925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
6025126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  When this function is called the function pointer is added to an internal list and any future calls to
6125126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  ReportStatusCode() will be forwarded to the Callback function. During the bootservices,
6225126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  this is the callback for which this service can be invoked. The report status code router
6325126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  will create an event such that the callback function is only invoked at the TPL for which it was
6425126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  registered. The entity that registers for the callback should also register for an event upon
6525126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  generation of exit boot services and invoke the unregister service.
6625126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  If the handler does not have a TPL dependency, it should register for a callback at TPL high. The
6725126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  router infrastructure will support making callbacks at runtime, but the caller for runtime invocation
6825126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  must meet the following criteria:
6925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  1. must be a runtime driver type so that its memory is not reclaimed
7025126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  2. not unregister at exit boot services so that the router will still have its callback address
7125126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  3. the caller must be self-contained (eg. Not call out into any boot-service interfaces) and be
7225126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  runtime safe, in general.
7325126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
7425126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @param[in] Callback   A pointer to a function of type EFI_RSC_HANDLER_CALLBACK that is called when
7525126a0530371f7a8e20bf663cc1beaf3eebd6f2xli                        a call to ReportStatusCode() occurs.
7625126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @param[in] Tpl        TPL at which callback can be safely invoked.
7725126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
7825126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @retval  EFI_SUCCESS              Function was successfully registered.
7925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @retval  EFI_INVALID_PARAMETER    The callback function was NULL.
8025126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @retval  EFI_OUT_OF_RESOURCES     The internal buffer ran out of space. No more functions can be
8125126a0530371f7a8e20bf663cc1beaf3eebd6f2xli                                    registered.
8225126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @retval  EFI_ALREADY_STARTED      The function was already registered. It can't be registered again.
8325126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
8425126a0530371f7a8e20bf663cc1beaf3eebd6f2xli**/
8525126a0530371f7a8e20bf663cc1beaf3eebd6f2xliEFI_STATUS
8625126a0530371f7a8e20bf663cc1beaf3eebd6f2xliEFIAPI
8725126a0530371f7a8e20bf663cc1beaf3eebd6f2xliRegister (
8825126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  IN EFI_RSC_HANDLER_CALLBACK   Callback,
8925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  IN EFI_TPL                    Tpl
9025126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  );
9125126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
9225126a0530371f7a8e20bf663cc1beaf3eebd6f2xli/**
9325126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  Remove a previously registered callback function from the notification list.
9425126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
9525126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  A callback function must be unregistered before it is deallocated. It is important that any registered
9625126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  callbacks that are not runtime complaint be unregistered when ExitBootServices() is called.
9725126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
9825126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @param[in]  Callback  A pointer to a function of type EFI_RSC_HANDLER_CALLBACK that is to be
9925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli                        unregistered.
10025126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
10125126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @retval EFI_SUCCESS           The function was successfully unregistered.
10225126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @retval EFI_INVALID_PARAMETER The callback function was NULL.
10325126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @retval EFI_NOT_FOUND         The callback function was not found to be unregistered.
10425126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
10525126a0530371f7a8e20bf663cc1beaf3eebd6f2xli**/
10625126a0530371f7a8e20bf663cc1beaf3eebd6f2xliEFI_STATUS
10725126a0530371f7a8e20bf663cc1beaf3eebd6f2xliEFIAPI
10825126a0530371f7a8e20bf663cc1beaf3eebd6f2xliUnregister (
10925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  IN EFI_RSC_HANDLER_CALLBACK Callback
11025126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  );
11125126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
11225126a0530371f7a8e20bf663cc1beaf3eebd6f2xli/**
11325126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  Provides an interface that a software module can call to report a status code.
11425126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
11525126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @param  Type             Indicates the type of status code being reported.
11625126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @param  Value            Describes the current status of a hardware or software entity.
11725126a0530371f7a8e20bf663cc1beaf3eebd6f2xli                           This included information about the class and subclass that is used to
11825126a0530371f7a8e20bf663cc1beaf3eebd6f2xli                           classify the entity as well as an operation.
11925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @param  Instance         The enumeration of a hardware or software entity within
12025126a0530371f7a8e20bf663cc1beaf3eebd6f2xli                           the system. Valid instance numbers start with 1.
12125126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @param  CallerId         This optional parameter may be used to identify the caller.
12225126a0530371f7a8e20bf663cc1beaf3eebd6f2xli                           This parameter allows the status code driver to apply different rules to
12325126a0530371f7a8e20bf663cc1beaf3eebd6f2xli                           different callers.
12425126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @param  Data             This optional parameter may be used to pass additional data.
12525126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
12625126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @retval EFI_SUCCESS           The function completed successfully
12725126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  @retval EFI_DEVICE_ERROR      The function should not be completed due to a device error.
12825126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
12925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli**/
13025126a0530371f7a8e20bf663cc1beaf3eebd6f2xliEFI_STATUS
13125126a0530371f7a8e20bf663cc1beaf3eebd6f2xliEFIAPI
13225126a0530371f7a8e20bf663cc1beaf3eebd6f2xliReportDispatcher (
13325126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  IN EFI_STATUS_CODE_TYPE     Type,
13425126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  IN EFI_STATUS_CODE_VALUE    Value,
13525126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  IN UINT32                   Instance,
13625126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  IN EFI_GUID                 *CallerId  OPTIONAL,
13725126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  IN EFI_STATUS_CODE_DATA     *Data      OPTIONAL
13825126a0530371f7a8e20bf663cc1beaf3eebd6f2xli  );
13925126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
14025126a0530371f7a8e20bf663cc1beaf3eebd6f2xli#endif
14125126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
14225126a0530371f7a8e20bf663cc1beaf3eebd6f2xli
143