hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/** @file
  This file include all platform action which can be customized by IBV/OEM.
 
Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
 
**/
 
#include "BdsPlatform.h"
 
extern UINTN                                   mBootMenuOptionNumber;
 
VOID
ExitPmAuth (
  VOID
  )
{
  EFI_HANDLE                 Handle;
  EFI_STATUS                 Status;
  EFI_EVENT                  EndOfDxeEvent;
 
  DEBUG((DEBUG_INFO,"ExitPmAuth ()- Start\n"));
  //
  // Prepare S3 information, this MUST be done before ExitPmAuth/EndOfDxe
  //
  //
  // Since PI1.2.1, we need signal EndOfDxe as ExitPmAuth
  //
  Status = gBS->CreateEventEx (
                  EVT_NOTIFY_SIGNAL,
                  TPL_CALLBACK,
                  EfiEventEmptyFunction,
                  NULL,
                  &gEfiEndOfDxeEventGroupGuid,
                  &EndOfDxeEvent
                  );
  ASSERT_EFI_ERROR (Status);
  gBS->SignalEvent (EndOfDxeEvent);
  gBS->CloseEvent (EndOfDxeEvent);
  DEBUG((DEBUG_INFO,"All EndOfDxe callbacks have returned successfully\n"));
 
  //
  // NOTE: We need install DxeSmmReadyToLock directly here because many boot script is added via ExitPmAuth/EndOfDxe callback.
  // If we install them at same callback, these boot script will be rejected because BootScript Driver runs first to lock them done.
  // So we seperate them to be 2 different events, ExitPmAuth is last chance to let platform add boot script. DxeSmmReadyToLock will
  // make boot script save driver lock down the interface.
  //
  Handle = NULL;
  Status = gBS->InstallProtocolInterface (
                  &Handle,
                  &gEfiDxeSmmReadyToLockProtocolGuid,
                  EFI_NATIVE_INTERFACE,
                  NULL
                  );
  ASSERT_EFI_ERROR (Status);
  DEBUG((DEBUG_INFO,"ExitPmAuth ()- End\n"));
}
 
 
/**
  Creates an EFI event in the BDS Event Group.
 
  @param  NotifyTpl         The task priority level of the event.
  @param  gEfiEventGuid     The GUID of the event group to signal.
  @param  BdsConsoleEvent   Returns the EFI event returned from gBS->CreateEvent(Ex).
 
  @retval EFI_SUCCESS       Event was created.
  @retval Other             Event was not created.
 
**/
EFI_STATUS
EFIAPI
CreateBdsEvent (
  IN  EFI_TPL           NotifyTpl,
  IN  EFI_GUID          *gEfiEventGuid,
  OUT EFI_EVENT         *BdsConsoleEvent
  )
{
  EFI_STATUS        Status;
 
  ASSERT (BdsConsoleEvent != NULL);
 
  Status = gBS->CreateEventEx (
                  EVT_NOTIFY_SIGNAL,
                  NotifyTpl,
                  EfiEventEmptyFunction,
                  NULL,
                  gEfiEventGuid,
                  BdsConsoleEvent
                  );
 
  return Status;
}
 
/**
  Create, Signal, and Close the Bds Event Before Console After
  Trusted Console event using CreateBdsEvent().
 
**/
VOID
EFIAPI
BdsSignalEventBeforeConsoleAfterTrustedConsole (
  VOID
  )
{
  EFI_STATUS    Status;
  EFI_EVENT     BdsConsoleEvent;
 
  DEBUG ((DEBUG_INFO, "%a \n", __FUNCTION__));
 
  Status = CreateBdsEvent (
             TPL_CALLBACK,
             &gBdsEventBeforeConsoleAfterTrustedConsoleGuid,
             &BdsConsoleEvent
             );
 
  ASSERT_EFI_ERROR (Status);
 
  if (!EFI_ERROR (Status)) {
    gBS->SignalEvent (BdsConsoleEvent);
    gBS->CloseEvent (BdsConsoleEvent);
    DEBUG ((DEBUG_INFO,"All EventBeforeConsoleAfterTrustedConsole callbacks have returned successfully\n"));
  }
}
 
 
/**
  Create, Signal, and Close the Bds Before Console Before End Of Dxe
  event using CreateBdsEvent().
**/
VOID
EFIAPI
BdsSignalEventBeforeConsoleBeforeEndOfDxe (
  VOID
  )
{
  EFI_STATUS    Status;
  EFI_EVENT     BdsConsoleEvent;
 
  DEBUG ((DEBUG_INFO, "%a \n", __FUNCTION__));
 
  Status = CreateBdsEvent (
             TPL_CALLBACK,
             &gBdsEventBeforeConsoleBeforeEndOfDxeGuid,
             &BdsConsoleEvent
             );
 
   ASSERT_EFI_ERROR (Status);
 
  if (!EFI_ERROR (Status)) {
    gBS->SignalEvent (BdsConsoleEvent);
    gBS->CloseEvent (BdsConsoleEvent);
    DEBUG ((DEBUG_INFO,"All BeforeConsoleBeforeEndOfDxe callbacks have returned successfully\n"));
  }
}
 
/**
  Create, Signal, and Close the Bds After Console Ready Before Boot Option
  using CreateBdsEvent().
**/
VOID
EFIAPI
BdsSignalEventAfterConsoleReadyBeforeBootOption (
  VOID
  )
{
  EFI_STATUS    Status;
  EFI_EVENT     BdsConsoleEvent;
 
  DEBUG ((DEBUG_INFO, "%a \n", __FUNCTION__));
 
  Status = CreateBdsEvent (
             TPL_CALLBACK,
             &gBdsEventAfterConsoleReadyBeforeBootOptionGuid,
             &BdsConsoleEvent
             );
 
  ASSERT_EFI_ERROR (Status);
 
  if (!EFI_ERROR (Status)) {
    gBS->SignalEvent (BdsConsoleEvent);
    gBS->CloseEvent (BdsConsoleEvent);
    DEBUG ((DEBUG_INFO,"All AfterConsoleReadyBeforeBootOption callbacks have returned successfully\n"));
  }
}
 
 
/**
  Platform Bds init. Incude the platform firmware vendor, revision
  and so crc check.
**/
VOID
EFIAPI
PlatformBootManagerBeforeConsole (
  VOID
  )
{
 
  DEBUG ((EFI_D_INFO, "PlatformBootManagerBeforeConsole\n"));
 
  //
  // Trusted console can be added in a PciEnumComplete callback
  //
 
  //
  // Signal Before Console, after Trusted console Event
  //
  BdsSignalEventBeforeConsoleAfterTrustedConsole ();
 
  //
  // Signal Before Console, before End of Dxe
  //
  BdsSignalEventBeforeConsoleBeforeEndOfDxe ();
 
  //
  // Signal End Of Dxe Event
  //
  PERF_START_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7020);
  ExitPmAuth ();
  PERF_END_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7021);
 
  //
  // Deferred 3rd party images can be dispatched in
  // an SmmReadyToLock callback
  //
}
 
 
/**
  The function will excute with as the platform policy, current policy
  is driven by boot mode. IBV/OEM can customize this code for their specific
  policy action.
 
  @param DriverOptionList - The header of the driver option link list
  @param BootOptionList   - The header of the boot option link list
  @param ProcessCapsules  - A pointer to ProcessCapsules()
  @param BaseMemoryTest   - A pointer to BaseMemoryTest()
**/
VOID
EFIAPI
PlatformBootManagerAfterConsole (
  VOID
  )
{
  DEBUG ((EFI_D_INFO, "PlatformBootManagerAfterConsole\n"));
 
  BdsSignalEventAfterConsoleReadyBeforeBootOption ();
}
 
/**
  The function is called when no boot option could be launched,
  including platform recovery options and options pointing to applications
  built into firmware volumes.
 
  If this function returns, BDS attempts to enter an infinite loop.
**/
VOID
EFIAPI
PlatformBootManagerUnableToBoot (
  VOID
  )
{
  BoardBootManagerUnableToBoot ();
}
 
/**
  This function is called each second during the boot manager waits the timeout.
 
  @param TimeoutRemain  The remaining timeout.
**/
VOID
EFIAPI
PlatformBootManagerWaitCallback (
  UINT16          TimeoutRemain
  )
{
  BoardBootManagerWaitCallback (TimeoutRemain);
}