]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFspWrapperPkg/FspNotifyDxe/FspNotifyDxe.c
f8e8e826f135a3491b087cb7e97d53ba6b4a094a
[mirror_edk2.git] / IntelFspWrapperPkg / FspNotifyDxe / FspNotifyDxe.c
1 /** @file
2 This driver will register two callbacks to call fsp's notifies.
3
4 Copyright (c) 2014 - 2015, 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 <PiDxe.h>
16
17 #include <Protocol/PciEnumerationComplete.h>
18
19 #include <Library/UefiDriverEntryPoint.h>
20 #include <Library/UefiBootServicesTableLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/UefiLib.h>
24 #include <Library/FspApiLib.h>
25
26 FSP_INFO_HEADER *mFspHeader = NULL;
27
28 /**
29 PciEnumerationComplete Protocol notification event handler.
30
31 @param[in] Event Event whose notification function is being invoked.
32 @param[in] Context Pointer to the notification function's context.
33 **/
34 VOID
35 EFIAPI
36 OnPciEnumerationComplete (
37 IN EFI_EVENT Event,
38 IN VOID *Context
39 )
40 {
41 NOTIFY_PHASE_PARAMS NotifyPhaseParams;
42 EFI_STATUS Status;
43 VOID *Interface;
44
45 //
46 // Try to locate it because gEfiPciEnumerationCompleteProtocolGuid will trigger it once when registration.
47 // Just return if it is not found.
48 //
49 Status = gBS->LocateProtocol (
50 &gEfiPciEnumerationCompleteProtocolGuid,
51 NULL,
52 &Interface
53 );
54 if (EFI_ERROR (Status)) {
55 return ;
56 }
57
58 NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration;
59 Status = CallFspNotifyPhase (mFspHeader, &NotifyPhaseParams);
60 if (Status != EFI_SUCCESS) {
61 DEBUG((DEBUG_ERROR, "FSP NotifyPhase AfterPciEnumeration failed, status: 0x%x\n", Status));
62 } else {
63 DEBUG((DEBUG_INFO, "FSP NotifyPhase AfterPciEnumeration Success.\n"));
64 }
65 }
66
67 /**
68 Notification function of EVT_GROUP_READY_TO_BOOT event group.
69
70 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.
71 When the Boot Manager is about to load and execute a boot option, it reclaims variable
72 storage if free size is below the threshold.
73
74 @param[in] Event Event whose notification function is being invoked.
75 @param[in] Context Pointer to the notification function's context.
76
77 **/
78 VOID
79 EFIAPI
80 OnReadyToBoot (
81 IN EFI_EVENT Event,
82 IN VOID *Context
83 )
84 {
85 NOTIFY_PHASE_PARAMS NotifyPhaseParams;
86 EFI_STATUS Status;
87
88 gBS->CloseEvent (Event);
89
90 NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;
91 Status = CallFspNotifyPhase (mFspHeader, &NotifyPhaseParams);
92 if (Status != EFI_SUCCESS) {
93 DEBUG((DEBUG_ERROR, "FSP NotifyPhase ReadyToBoot failed, status: 0x%x\n", Status));
94 } else {
95 DEBUG((DEBUG_INFO, "FSP NotifyPhase ReadyToBoot Success.\n"));
96 }
97 }
98
99 /**
100 Main entry for the FSP DXE module.
101
102 This routine registers two callbacks to call fsp's notifies.
103
104 @param[in] ImageHandle The firmware allocated handle for the EFI image.
105 @param[in] SystemTable A pointer to the EFI System Table.
106
107 @retval EFI_SUCCESS The entry point is executed successfully.
108 @retval other Some error occurs when executing this entry point.
109
110 **/
111 EFI_STATUS
112 EFIAPI
113 FspDxeEntryPoint (
114 IN EFI_HANDLE ImageHandle,
115 IN EFI_SYSTEM_TABLE *SystemTable
116 )
117 {
118 EFI_STATUS Status;
119 EFI_EVENT ReadyToBootEvent;
120 VOID *Registration;
121 EFI_EVENT ProtocolNotifyEvent;
122
123 if (PcdGet32 (PcdFlashFvSecondFspBase) == 0) {
124 mFspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase));
125 } else {
126 mFspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvSecondFspBase));
127 }
128 DEBUG ((DEBUG_INFO, "FspHeader - 0x%x\n", mFspHeader));
129 if (mFspHeader == NULL) {
130 return EFI_DEVICE_ERROR;
131 }
132
133 ProtocolNotifyEvent = EfiCreateProtocolNotifyEvent (
134 &gEfiPciEnumerationCompleteProtocolGuid,
135 TPL_CALLBACK,
136 OnPciEnumerationComplete,
137 NULL,
138 &Registration
139 );
140 ASSERT (ProtocolNotifyEvent != NULL);
141
142 Status = EfiCreateEventReadyToBootEx (
143 TPL_CALLBACK,
144 OnReadyToBoot,
145 NULL,
146 &ReadyToBootEvent
147 );
148 ASSERT_EFI_ERROR (Status);
149
150 return EFI_SUCCESS;
151 }
152