Home | History | Annotate | Download | only in PiSmbiosRecordOnDataHubSmbiosRecordThunk
      1 /** @file
      2   Thunk driver's entry that install filter for DataRecord.
      3 
      4 Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
      5 This program and the accompanying materials
      6 are licensed and made available under the terms and conditions of the BSD License
      7 which accompanies this distribution.  The full text of the license may be found at
      8 http://opensource.org/licenses/bsd-license.php
      9 
     10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 
     13 **/
     14 
     15 #include "Thunk.h"
     16 
     17 //
     18 // Global variables
     19 //
     20 LIST_ENTRY  mStructureList;
     21 
     22 /**
     23   Entry Point of thunk driver.
     24 
     25   @param[in] ImageHandle  Image handle of this driver.
     26   @param[in] SystemTable  Pointer to EFI system table.
     27 
     28   @retval EFI_SUCCESS          The event handlers were registered.
     29   @retval EFI_DEVICE_ERROR     Failed to register the event handlers
     30 **/
     31 EFI_STATUS
     32 EFIAPI
     33 ThunkEntry (
     34   IN EFI_HANDLE         ImageHandle,
     35   IN EFI_SYSTEM_TABLE   *SystemTable
     36   )
     37 {
     38   EFI_STATUS            Status;
     39   EFI_DATA_HUB_PROTOCOL *DataHub;
     40   EFI_EVENT             FilterEvent;
     41 
     42   Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID**) &DataHub);
     43   ASSERT_EFI_ERROR (Status);
     44   ASSERT (DataHub != NULL);
     45 
     46   InitializeListHead (&mStructureList);
     47 
     48   //
     49   // Register SmBios Data Filter Function.
     50   // This function is notified at TPL_CALLBACK.
     51   //
     52   Status = gBS->CreateEvent (
     53                   EVT_NOTIFY_SIGNAL,
     54                   TPL_CALLBACK,
     55                   SmbiosDataFilter,
     56                   NULL,
     57                   &FilterEvent
     58                   );
     59   if (EFI_ERROR (Status)) {
     60     return Status;
     61   }
     62 
     63   Status = DataHub->RegisterFilterDriver (
     64                       DataHub,
     65                       FilterEvent,
     66                       TPL_APPLICATION,
     67                       EFI_DATA_RECORD_CLASS_DATA,
     68                       NULL
     69                       );
     70   if (EFI_ERROR (Status)) {
     71     gBS->CloseEvent (FilterEvent);
     72     return Status;
     73   }
     74 
     75   return Status;
     76 
     77 }
     78 
     79 /**
     80   Smbios data filter function. This function is invoked when there is data records
     81   available in the Data Hub.
     82 
     83   @param Event         The event that is signaled.
     84   @param Context       not used here.
     85 **/
     86 VOID
     87 EFIAPI
     88 SmbiosDataFilter (
     89   IN EFI_EVENT    Event,
     90   IN VOID         *Context
     91   )
     92 {
     93   EFI_STATUS              Status;
     94   EFI_DATA_HUB_PROTOCOL   *DataHub;
     95   EFI_HANDLE              DataHubHandle;
     96   UINTN                   HandleSize;
     97   UINT64                  MonotonicCount;
     98   EFI_DATA_RECORD_HEADER  *Record;
     99 
    100   Status  = EFI_SUCCESS;
    101   DataHub = NULL;
    102 
    103   //
    104   // Get the Data Hub Protocol. Assume only one instance
    105   // of Data Hub Protocol is available in the system.
    106   //
    107   HandleSize = sizeof (EFI_HANDLE);
    108 
    109   Status = gBS->LocateHandle (
    110                   ByProtocol,
    111                   &gEfiDataHubProtocolGuid,
    112                   NULL,
    113                   &HandleSize,
    114                   &DataHubHandle
    115                   );
    116 
    117   if (EFI_ERROR (Status)) {
    118     goto Done;
    119   }
    120 
    121   Status = gBS->HandleProtocol (
    122                   DataHubHandle,
    123                   &gEfiDataHubProtocolGuid,
    124                   (VOID **) &DataHub
    125                   );
    126 
    127   if (EFI_ERROR (Status)) {
    128     goto Done;
    129   }
    130   //
    131   // Get all available data records from data hub
    132   //
    133   MonotonicCount  = 0;
    134   Record          = NULL;
    135 
    136   do {
    137 
    138     Status = DataHub->GetNextRecord (
    139                         DataHub,
    140                         &MonotonicCount,
    141                         &Event,
    142                         &Record
    143                         );
    144 
    145     if (!EFI_ERROR (Status)) {
    146       if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
    147 
    148         //
    149         // It's of expected Data Type. Process it.
    150         //
    151         SmbiosProcessDataRecord (Record);
    152       }
    153     }
    154   } while (!EFI_ERROR (Status) && (MonotonicCount != 0));
    155 
    156 Done:
    157 
    158   return ;
    159 
    160 }
    161