hc
2024-03-25 edb30157bad0c0001c32b854271ace01d3b9a16a
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
/** @file
  Bds Hook Point callbacks DXE driver
 
  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
  SPDX-License-Identifier: BSD-2-Clause-Patent
 
**/
 
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiLib.h>
#include <Library/BoardBdsHookLib.h>
 
#include <Protocol/PciEnumerationComplete.h>
 
/**
  Initialize  DXE Platform.
 
  @param[in] ImageHandle       Image handle of this driver.
  @param[in] SystemTable       Global system service table.
 
  @retval EFI_SUCCESS           Initialization complete.
  @exception EFI_UNSUPPORTED       The chipset is unsupported by this driver.
  @retval EFI_OUT_OF_RESOURCES  Do not have enough resources to initialize the driver.
  @retval EFI_DEVICE_ERROR      Device error, driver exits abnormally.
**/
EFI_STATUS
EFIAPI
BdsHookDxeEntryPoint (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE *SystemTable
  )
{
  EFI_EVENT   BeforeConsoleAfterTrustedConsoleEvent;
  EFI_EVENT   BeforeConsoleBeforeEndOfDxeEvent;
  EFI_EVENT   AfterConsoleReadyBeforeBootOptionEvent;
  EFI_EVENT   ReadyToBootEvent;
  EFI_EVENT   PciEnumCompleteEvent;
  EFI_EVENT   SmmReadyToLockEvent;
  EFI_STATUS  Status;
  VOID        *Registration;
 
  DEBUG ((DEBUG_INFO, "%a starts\n", __FUNCTION__ ));
 
  //
  // Create event to set proper video resolution and text mode for internal shell.
  //
  Status = EfiCreateEventReadyToBootEx (
             TPL_CALLBACK,
             BdsReadyToBootCallback,
             NULL,
             &ReadyToBootEvent
             );
  ASSERT_EFI_ERROR (Status);
 
  //
  // Create PCI Enumeration Completed callback for BDS
  //
  PciEnumCompleteEvent = EfiCreateProtocolNotifyEvent (
                           &gEfiPciEnumerationCompleteProtocolGuid,
                           TPL_CALLBACK,
                           BdsPciEnumCompleteCallback,
                           NULL,
                           &Registration
                           );
  ASSERT (PciEnumCompleteEvent != NULL);
 
  //
  // Create PCI Enumeration Completed callback for BDS
  //
  SmmReadyToLockEvent = EfiCreateProtocolNotifyEvent (
                          &gEfiDxeSmmReadyToLockProtocolGuid,
                          TPL_CALLBACK,
                          BdsSmmReadyToLockCallback,
                          NULL,
                          &Registration
                          );
  ASSERT (SmmReadyToLockEvent != NULL);
 
  //
  // Create BeforeConsoleAfterTrustedConsole event callback
  //
  Status = gBS->CreateEventEx (
                  EVT_NOTIFY_SIGNAL,
                  TPL_CALLBACK,
                  BdsBeforeConsoleAfterTrustedConsoleCallback,
                  NULL,
                  &gBdsEventBeforeConsoleAfterTrustedConsoleGuid,
                  &BeforeConsoleAfterTrustedConsoleEvent
                  );
  ASSERT_EFI_ERROR (Status);
 
  //
  // Create BeforeConsoleBeforeEndOfDxeGuid event callback
  //
  Status = gBS->CreateEventEx (
                  EVT_NOTIFY_SIGNAL,
                  TPL_CALLBACK,
                  BdsBeforeConsoleBeforeEndOfDxeGuidCallback,
                  NULL,
                  &gBdsEventBeforeConsoleBeforeEndOfDxeGuid,
                  &BeforeConsoleBeforeEndOfDxeEvent
                  );
  ASSERT_EFI_ERROR (Status);
 
  //
  // Create AfterConsoleReadyBeforeBootOption event callback
  //
  Status = gBS->CreateEventEx (
                  EVT_NOTIFY_SIGNAL,
                  TPL_CALLBACK,
                  BdsAfterConsoleReadyBeforeBootOptionCallback,
                  NULL,
                  &gBdsEventAfterConsoleReadyBeforeBootOptionGuid,
                  &AfterConsoleReadyBeforeBootOptionEvent
                  );
  ASSERT_EFI_ERROR (Status);
 
  return Status;
}