blob: 859b26728d7c51852363b66bfdc7794e139b8575 [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/** @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
26FSP_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**/
34VOID
35EFIAPI
36OnPciEnumerationComplete (
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**/
78VOID
79EFIAPI
80OnReadyToBoot (
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**/
111EFI_STATUS
112EFIAPI
113FspDxeEntryPoint (
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 mFspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase));
124 DEBUG ((DEBUG_INFO, "FspHeader - 0x%x\n", mFspHeader));
125 if (mFspHeader == NULL) {
126 return EFI_DEVICE_ERROR;
127 }
128
129 ProtocolNotifyEvent = EfiCreateProtocolNotifyEvent (
130 &gEfiPciEnumerationCompleteProtocolGuid,
131 TPL_CALLBACK,
132 OnPciEnumerationComplete,
133 NULL,
134 &Registration
135 );
136 ASSERT (ProtocolNotifyEvent != NULL);
137
138 Status = EfiCreateEventReadyToBootEx (
139 TPL_CALLBACK,
140 OnReadyToBoot,
141 NULL,
142 &ReadyToBootEvent
143 );
144 ASSERT_EFI_ERROR (Status);
145
146 return EFI_SUCCESS;
147}
148