summaryrefslogtreecommitdiff
path: root/EdkCompatibilityPkg/Compatibility/PiSmbiosRecordOnDataHubSmbiosRecordThunk/Thunk.c
blob: 7d3f5d036ba32f065e6e82c99d9d3bb4d58688fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/** @file
  Thunk driver's entry that install filter for DataRecord.
  
Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution.  The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include "Thunk.h"

//
// Global variables
//
LIST_ENTRY  mStructureList;

/**
  Entry Point of thunk driver.

  @param[in] ImageHandle  Image handle of this driver.
  @param[in] SystemTable  Pointer to EFI system table.

  @retval EFI_SUCCESS          The event handlers were registered.
  @retval EFI_DEVICE_ERROR     Failed to register the event handlers
**/  
EFI_STATUS
EFIAPI
ThunkEntry (
  IN EFI_HANDLE         ImageHandle,
  IN EFI_SYSTEM_TABLE   *SystemTable
  )
{
  EFI_STATUS            Status;
  EFI_DATA_HUB_PROTOCOL *DataHub;
  EFI_EVENT             FilterEvent;
    
  Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID**) &DataHub);
  ASSERT_EFI_ERROR (Status);
  ASSERT (DataHub != NULL);

  InitializeListHead (&mStructureList);

  //
  // Register SmBios Data Filter Function.
  // This function is notified at TPL_CALLBACK.
  //
  Status = gBS->CreateEvent (
                  EVT_NOTIFY_SIGNAL,
                  TPL_CALLBACK,
                  SmbiosDataFilter,
                  NULL,
                  &FilterEvent
                  );
  if (EFI_ERROR (Status)) {
    return Status;
  }

  Status = DataHub->RegisterFilterDriver (
                      DataHub,
                      FilterEvent,
                      TPL_APPLICATION,
                      EFI_DATA_RECORD_CLASS_DATA,
                      NULL
                      );
  if (EFI_ERROR (Status)) {
    gBS->CloseEvent (FilterEvent);
    return Status;
  }

  return Status;

} 

/**
  Smbios data filter function. This function is invoked when there is data records
  available in the Data Hub. 

  @param Event         The event that is signaled.
  @param Context       not used here.
**/
VOID
EFIAPI
SmbiosDataFilter (
  IN EFI_EVENT    Event,
  IN VOID         *Context
  )
{
  EFI_STATUS              Status;
  EFI_DATA_HUB_PROTOCOL   *DataHub;
  EFI_HANDLE              DataHubHandle;
  UINTN                   HandleSize;
  UINT64                  MonotonicCount;
  EFI_DATA_RECORD_HEADER  *Record;

  Status  = EFI_SUCCESS;
  DataHub = NULL;

  //
  // Get the Data Hub Protocol. Assume only one instance
  // of Data Hub Protocol is availabe in the system.
  //
  HandleSize = sizeof (EFI_HANDLE);

  Status = gBS->LocateHandle (
                  ByProtocol,
                  &gEfiDataHubProtocolGuid,
                  NULL,
                  &HandleSize,
                  &DataHubHandle
                  );

  if (EFI_ERROR (Status)) {
    goto Done;
  }

  Status = gBS->HandleProtocol (
                  DataHubHandle,
                  &gEfiDataHubProtocolGuid,
                  (VOID **) &DataHub
                  );

  if (EFI_ERROR (Status)) {
    goto Done;
  }
  //
  // Get all available data records from data hub
  //
  MonotonicCount  = 0;
  Record          = NULL;

  do {

    Status = DataHub->GetNextRecord (
                        DataHub,
                        &MonotonicCount,
                        &Event,
                        &Record
                        );

    if (!EFI_ERROR (Status)) {
      if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
      
        //
        // It's of expected Data Type. Process it.
        //
        SmbiosProcessDataRecord (Record);
      }
    }
  } while (!EFI_ERROR (Status) && (MonotonicCount != 0));

Done:

  return ;

}