1 /** @file
2 
3   Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>
4 
5 
6   This program and the accompanying materials are licensed and made available under
7 
8   the terms and conditions of the BSD License that accompanies this distribution.
9 
10   The full text of the license may be found at
11 
12   http://opensource.org/licenses/bsd-license.php.
13 
14 
15 
16   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 
18   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 
20 
21 
22 
23 
24   This file includes a memory call back function notified when MRC is done,
25   following action is performed in this file,
26     1. ICH initialization after MRC.
27     2. SIO initialization.
28     3. Install ResetSystem and FinvFv PPI.
29     4. Set MTRR for PEI
30     5. Create FV HOB and Flash HOB
31 
32 
33 **/
34 
35 
36 #include "CommonHeader.h"
37 #include "Platform.h"
38 #include <Ppi/Cache.h>
39 #include <Library/BaseCryptLib.h>
40 #include <Library/PciLib.h>
41 #include "VlvAccess.h"
42 
43 
44 EFI_PEI_PPI_DESCRIPTOR  mPpiListRecoveryBootMode[] = {
45 { (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
46   &gEfiPeiBootInRecoveryModePpiGuid,
47   NULL
48 }
49 };
50 
51 #if 0
52 STATIC
53 EFI_STATUS
54 GetMemorySize (
55   IN  CONST EFI_PEI_SERVICES    **PeiServices,
56   OUT UINT64              *LowMemoryLength,
57   OUT UINT64              *HighMemoryLength
58   )
59 {
60   EFI_STATUS              Status;
61   EFI_PEI_HOB_POINTERS    Hob;
62 
63   *HighMemoryLength = 0;
64   *LowMemoryLength = 0x100000;
65   //
66   // Get the HOB list for processing
67   //
68   Status = (*PeiServices)->GetHobList (PeiServices, (void **)&Hob.Raw);
69   if (EFI_ERROR(Status)) {
70     return Status;
71   }
72 
73   //
74   // Collect memory ranges
75   //
76   while (!END_OF_HOB_LIST (Hob)) {
77     if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
78       if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {
79         //
80         // Need memory above 1MB to be collected here
81         //
82         if (Hob.ResourceDescriptor->PhysicalStart >= 0x100000 &&
83             Hob.ResourceDescriptor->PhysicalStart < (EFI_PHYSICAL_ADDRESS) 0x100000000) {
84           *LowMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);
85         } else if (Hob.ResourceDescriptor->PhysicalStart >= (EFI_PHYSICAL_ADDRESS) 0x100000000) {
86           *HighMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);
87         }
88       }
89     }
90     Hob.Raw = GET_NEXT_HOB (Hob);
91   }
92 
93   return EFI_SUCCESS;
94 }
95 
96 #endif
97 /**
98   This function will be called when MRC is done.
MemoryDiscoveredPpiNotifyCallback(IN EFI_PEI_SERVICES ** PeiServices,IN EFI_PEI_NOTIFY_DESCRIPTOR * NotifyDescriptor,IN VOID * Ppi)99 
100   @param  PeiServices General purpose services available to every PEIM.
101   @param  NotifyDescriptor Information about the notify event..
102   @param  Ppi The notify context.
103 
104   @retval EFI_SUCCESS If the function completed successfully.
105 **/
106 EFI_STATUS
107 EFIAPI
108 MemoryDiscoveredPpiNotifyCallback (
109   IN EFI_PEI_SERVICES           **PeiServices,
110   IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,
111   IN VOID                       *Ppi
112   )
113 {
114 
115   EFI_STATUS       Status;
116   EFI_BOOT_MODE    BootMode;
117   UINT32           Pages;
118   VOID*            Memory;
119   UINTN            Size;
120 
121   //
122   // Allocate LM memory and configure PDM if enabled by user.
123   // ConfigureLM(PeiServices);
124   //
125   Status = (*PeiServices)->GetBootMode (
126                              (const EFI_PEI_SERVICES **)PeiServices,
127                              &BootMode
128                              );
129 
130   if (BootMode != BOOT_ON_S3_RESUME) {
131     Size = (PcdGet32 (PcdFlashFvRecovery2Base) - PcdGet32 (PcdFlashFvMainBase)) + FixedPcdGet32(PcdFlashFvRecovery2Size);
132     Pages=  Size/0x1000;
133 
134     Memory = AllocatePages ( Pages );
135     CopyMem(Memory , (VOID *) FixedPcdGet32(PcdFlashFvMainBase) , Size);
136 
137     //
138     // We don't verify just load
139     //
140     PeiServicesInstallFvInfoPpi (
141       NULL,
142       (VOID *) ((UINTN) Memory + (PcdGet32 (PcdFlashFvRecovery2Base) - PcdGet32 (PcdFlashFvMainBase))),
143       PcdGet32 (PcdFlashFvRecovery2Size),
144       NULL,
145       NULL
146       );
147 
148     PeiServicesInstallFvInfoPpi (
149       NULL,
150       (VOID *)  Memory,
151       PcdGet32 (PcdFlashFvMainSize),
152       NULL,
153       NULL
154       );
155 
156   }
157 
158   if (BootMode == BOOT_ON_S3_RESUME) {
159     PeiServicesInstallFvInfoPpi (
160     NULL,
161     (VOID *) (UINTN) (PcdGet32 (PcdFlashFvRecovery2Base)),
162     PcdGet32 (PcdFlashFvRecovery2Size),
163     NULL,
164     NULL
165     );
166   }
167 
168   return EFI_SUCCESS;
169 }
170