summaryrefslogtreecommitdiff
path: root/Core/EM/FastBoot/FastBootPei.c
blob: 508209534dd184ec5ccd0fdcfda25229ae9e499a (plain)
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
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2010, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************

//*************************************************************************
// $Header: /Alaska/SOURCE/Modules/PTT/FastBootPei.c 2     11/09/10 8:43a Bibbyyeh $
//
// $Revision: 2 $
//
// $Date: 11/09/10 8:43a $
//*************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/PTT/FastBootPei.c $
// 
// 2     11/09/10 8:43a Bibbyyeh
// [TAG]  		EIP47280
// [Category]  	New Feature
// [Description]  	Currently, BIOS will copy FV_MAIN or FV_BB into memory
// in DXE phase. If BIOS copy rom before CPU disable flash cache in PEI
// phase. Some data are in cache already, don't need to read from physical
// ROM. It can help to save some time.
// [Files]  		FastBootPei.c
// 
// 1     11/02/10 1:47a Bibbyyeh
// [TAG]  		EIP47280
// [Category]  	New Feature
// [Description]  	Currently, BIOS will copy FV_MAIN or FV_BB into memory
// in DXE phase.
// If BIOS copy rom before CPU disable flash cache in PEI phase.
// Some data are in cache already, don't need to read from physical ROM.
// It can help to save some time.
// [Files]  		FastBootPei.cif
// FastBootPei.mak
// FastBootPei.c
// FastBootPei.dxs
// 
//
//*************************************************************************
//<AMI_FHDR_START>
//
// Name:  FastBootPei.c
//
//  Description:
//  Fast Boot Pei Driver
//
//<AMI_FHDR_END>
//*************************************************************************

//============================================================================
// Includes
//============================================================================

#include <AmiPeiLib.h>
#include <Pei.h>
#include <Token.h>

//============================================================================
// Glocal Variable Declaration
//============================================================================
EFI_GUID gEfiPeiEndOfPeiPhasePpiGuid    = EFI_PEI_END_OF_PEI_PHASE_PPI_GUID;

EFI_STATUS NotifyAtPeiEnd (
    IN EFI_PEI_SERVICES             **PeiServices,
    IN EFI_PEI_NOTIFY_DESCRIPTOR    *NotifyDescriptor,
    IN VOID                         *Ppi
);

EFI_PEI_NOTIFY_DESCRIPTOR FastBootNotifyDescs = {
    EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
    &gEfiPeiEndOfPeiPhasePpiGuid,
    NotifyAtPeiEnd
};


//============================================================================
// Procedure
//============================================================================

VOID CopyRomImageToRam(EFI_PEI_SERVICES **PeiServices) 
{
	EFI_STATUS				Status;
 	VOID *p;
	EFI_HOB_FIRMWARE_VOLUME	*FvHob;
	EFI_PHYSICAL_ADDRESS  	MemoryBuffer;
	EFI_PHYSICAL_ADDRESS	FvHobAddress;
	UINT64					FvHobLength;

	for(  (*PeiServices)->GetHobList(PeiServices,&p)
		; !EFI_ERROR(FindNextHobByType(EFI_HOB_TYPE_FV,&p))
		;
	)
	{
		FvHob = (EFI_HOB_FIRMWARE_VOLUME*)p;
		FvHobAddress = FvHob->BaseAddress;
		FvHobLength = FvHob->Length;

		if ( FvHobAddress == FV_MAIN_BASE || FvHobAddress == FV_BB_BASE) {
            
			// Allocate Memory
			Status = (*PeiServices)->AllocatePages (
										PeiServices,
										EfiBootServicesData,
										EFI_SIZE_TO_PAGES ((UINT32)FvHobLength),
										&MemoryBuffer
									);
			ASSERT_PEI_ERROR (PeiServices, Status);

			// Copy FV HOB from ROM to RAM
	    	(*PeiServices)->CopyMem (
	                      		(VOID*)MemoryBuffer, 
	                      		(VOID*)FvHobAddress,
	                      		(UINTN)FvHobLength
	                      	);

			// Update FV HOB (BaseAddress)
			FvHob->BaseAddress = MemoryBuffer;
		} // end for
	} // end if
}


EFI_STATUS NotifyAtPeiEnd (
    IN EFI_PEI_SERVICES             **PeiServices,
    IN EFI_PEI_NOTIFY_DESCRIPTOR    *NotifyDescriptor,
    IN VOID                         *Ppi
)
{
	EFI_BOOT_MODE	BootMode;
	EFI_STATUS		Status;

    Status = (*PeiServices)->GetBootMode(PeiServices, &BootMode);
    ASSERT_PEI_ERROR(PeiServices, Status);


	if ( (BootMode != BOOT_ON_S3_RESUME) && (BootMode != BOOT_IN_RECOVERY_MODE) ) {
        CopyRomImageToRam(PeiServices);
	}
    return EFI_SUCCESS;
}


EFI_STATUS 
FastBootPeiEntry (
	IN EFI_FFS_FILE_HEADER		*FfsHeader,
	IN EFI_PEI_SERVICES		**PeiServices
  )
{
    (*PeiServices)->NotifyPpi(
        PeiServices,
        &FastBootNotifyDescs
    );
    
    
    return EFI_SUCCESS;
}

//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2010, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************