summaryrefslogtreecommitdiff
path: root/Core/EM/FastBoot/FastBootTseHook.c
blob: b3002446c84dd9104aca410f65a1a657b9683d15 (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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (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/FastBootTseHook.c 8     7/17/13 2:59a Simonchen $
//
// $Revision: 8 $
//
// $Date: 7/17/13 2:59a $
//*************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/PTT/FastBootTseHook.c $
// 
// 8     7/17/13 2:59a Simonchen
// [TAG]  		EIP125309
// [Category]  	New Feature
// [Description]  	Add function to make sure before boot to OS, BIOS is in
// fastboot path.
// [Files]  		FastBoot.sdl
// FastBootTseHook.c
// FastBoot.c
// FastBoot.h
// 
// 7     8/04/12 5:38a Bibbyyeh
// Fix logic defect in the if statement in procedure
// "FastBootCheckForKey".
// 
// 6     6/01/12 6:56a Bibbyyeh
// [TAG]           EIP90455
// [Category]      New Feature
// [Description]   PTT improvement - fastboot policy protocol for dynamic
// control fast boot behavior.
// [Files]         FastBoot.c FastBoot.sdl FastBoot.sd FastBoot.uni
// FastBootRuntime.c FastBootTseHook.c FastBootProtocol.h FastBoot.h
// 
// 5     5/30/12 3:38a Bibbyyeh
// [TAG]           EIP90874
// [Category]      Improvement
// [Description]   Display "Press the DEL or ESC key to enter setup"
// message in fastboot path.
// [Files]         FastBootTseHook.c
// 
// 4     9/08/11 5:26a Bibbyyeh
// [TAG]           EIP68329
// [Category]      Bug Fix
// [Severity]      Important
// [Symptom]       OS can't back to desktop correctly after resumed from
// S3. 
// [RootCause]     TSEIDEPasswordFreezeDevices is skipped in fastboot path
// if SKIP_TSE_HANDSHAKE is enabled. 
// [Solution]      Call TSEIDEPasswordFreezeDevices after ReadyToBoot
// Event in fastboot path.
// [Files]         FastBoot.c FastBootProtocol.h FastBootTseHook.c
// 
// 3     7/07/11 10:38a Bibbyyeh
// [TAG]           EIP63924
// [Category]      Improvement
// [Description]   
// 1. Add elink for FastBoot mode change, default checking rule is check
// post hotkey.
// 2. Timer call back for check hotkey is not necessary. Create a protocol
// for calling checkforkey in TSE.
// 3. Since EIP68383 improve the performance of ps2 keyboard, we don't
// need to exchange the initial order of ConIn/ConOut for getting more
// time to detect hotkey.
// [Files]         FastBoot.sdl FastBoot.mak FastBoot.c FastBootTseHook.c
// FastBoot.h FastBootProtocol.h
// 
// 2     3/11/11 10:01p Bibbyyeh
// [TAG]		EIP54993
// [Category]	Improvement
// [Description]
// 1.Sync with Fastboot_10
// 2.Remove token "SAVE_LAST_BOOT_DEVICE_CHECKSUM"
// 3.Add token "CALL_DISPATCHER_AGAIN_IN_FASTBOOT"
// 4.Use SimpleText protocol to detect mode change hotkey instead of
// pBS->ConIn.
// 5.Simplify the code about "AMILEGACY16_FASTBOOT_SOLUTION".
// 6.Fixed a bug that SATA device can't be found if keep TSE execution on
// fastboot path.
// [Files]		PPT.cif FastBoot.sdl FastBootRuntime.c FastBootTseHook.c
// FastBoot.c FastBoot.h FastBoot.sd FastBootProtocol.cif
// FastBootProtocol.h FastBootSMI.cif FastBootSMI.sdl FastBootSMI.c
// FastBootSMI.dxs FastBootSMI.mak
// 
// 1     10/12/10 9:04a Bibbyyeh
// Initial check in
// 
// 
//*************************************************************************
//<AMI_FHDR_START>
//
// Name:  FastBootTseHook.c
//
//  Description:
//  Implementation of suppress of TSE "Press DEL..." message
//
//<AMI_FHDR_END>
//*************************************************************************
//============================================================================
// Includes
//============================================================================

#include <Efi.h>
#include <Setup.h>
#include <Protocol/FastBootProtocol.h>
#include "FastBoot.h"
#include "AMITSEStrTokens.h"
#if FASTBOOT_NEED_RESTART
#include <AmiDxeLib.h>
#endif
//============================================================================
// Define
//============================================================================
#define	BOOT_FLOW_CONDITION_NORMAL	0

#if FASTBOOT_NEED_RESTART
static EFI_GUID FastbootRestartGuid = FAST_BOOT_RESTART_GUID;
static EFI_GUID FastbootRestartCountGuid = FAST_BOOT_RESTART_COUNT_GUID;
#endif

//============================================================================
// External Golbal Variable Declaration
//============================================================================
extern EFI_RUNTIME_SERVICES *gRT;
extern EFI_BOOT_SERVICES 	*gBS;
extern UINT32 gBootFlow;
extern BOOLEAN gEnterSetup;
extern EFI_EVENT gKeyTimer;
extern CHAR16 *HiiGetString( VOID* handle, UINT16 token );
extern EFI_HII_HANDLE  gHiiHandle;
//============================================================================
// External Function Definitions
//============================================================================
EFI_STATUS PostManagerDisplayPostMessage( CHAR16 *message );
BOOLEAN ProcessConInAvailability(VOID);
VOID BbsBoot(VOID);
VOID TSEIDEPasswordFreezeDevices(); 	//(EIP68329)+
VOID CheckForKeyHook( EFI_EVENT Event, VOID *Context );
EFI_STATUS TimerStopTimer( EFI_EVENT *Event );    
//============================================================================
// Golbal Variable Declaration
//============================================================================
FAST_BOOT_POLICY    *gFastBootPolicy;
FAST_BOOT_TSE_PROTOCOL gFastBootTseProtocol = {
    FastBootCheckForKey,
    FastBootStopCheckForKeyTimer,
    TSEIDEPasswordFreezeDevices         //(EIP68329)++
};
//============================================================================
// Function Definitions
//============================================================================
										//(EIP63924+)>
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	FastBootCheckForKey
//
// Description:	This function check TSE variable,gEnterSetup and gBootFlow.
//              
// Input:		
//          BOOLEAN *EnterSetup
//          UINT32  *BootFlow
// Output:		
//          EFI_SUCCESS - Bootflow is changed or EnterSetup if true
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS FastBootCheckForKey( 
    IN  BOOLEAN *EnterSetup,
    IN  UINT32  *BootFlow)
{
    CheckForKeyHook( (EFI_EVENT)NULL, NULL );

    *EnterSetup = gEnterSetup;
    *BootFlow = gBootFlow;
    
    if ((gEnterSetup) || (gBootFlow != BOOT_FLOW_CONDITION_NORMAL)){
        return EFI_SUCCESS;
    }
    else { 
    	return EFI_NOT_READY;
    }
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	FastBootStopCheckForKeyTimer
//
// Description:	This function stop the timer of CheckForKey callback
//
// Input:		None
//
// Output:		EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>                                        
EFI_STATUS FastBootStopCheckForKeyTimer()
{
    return TimerStopTimer(&gKeyTimer);
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   FastBootMinisetupDriverEntryHook
//
// Description: Function that will be called when enter TSE Dxe entry
//
// Input:		
//  None
//
// Output:
//  FALSE - as per TSE requirement, that no password was entered
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID FastBootMinisetupDriverEntryHook(VOID)
{
    EFI_HANDLE Handle = NULL;			
    EFI_GUID   FastBootTseGuid = FAST_BOOT_TSE_PROTOCOL_GUID; 
    EFI_GUID   FastBootPolicyGuid = FAST_BOOT_POLICY_PROTOCOL_GUID;
    EFI_STATUS Status;
    
    gBS->InstallProtocolInterface(&Handle,
                              &FastBootTseGuid,
                              EFI_NATIVE_INTERFACE,
                              &gFastBootTseProtocol);

    Status = gBS->LocateProtocol(&FastBootPolicyGuid,NULL,&gFastBootPolicy);
        
} 
										//<(EIP63924+)
#if FASTBOOT_NEED_RESTART										
VOID InitialRebootCount(VOID)
{
	EFI_STATUS Status;
	UINTN RebootFlag = 1;
	UINTN RebootFlagSize = sizeof(RebootFlag);
	UINTN ClearCount = 0;
	UINTN ClearCountSize = sizeof(ClearCount); 
	Status = gRT->SetVariable(FAST_BOOT_RESTART_COUNT, 
				&FastbootRestartCountGuid, 
				EFI_VARIABLE_NON_VOLATILE |
				EFI_VARIABLE_BOOTSERVICE_ACCESS |
				EFI_VARIABLE_RUNTIME_ACCESS,
				ClearCountSize,
				&ClearCount);

	Status = gRT->SetVariable(FAST_BOOT_RESTART, 
				&FastbootRestartGuid, 
				EFI_VARIABLE_NON_VOLATILE |
				EFI_VARIABLE_BOOTSERVICE_ACCESS |
				EFI_VARIABLE_RUNTIME_ACCESS,
				RebootFlagSize,
				&RebootFlag);

}
#endif
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   FastBootConInAvailHook
//
// Description: Function that will be called instead of generic TSE callback
//              on Console Input device is installed event
//
// Input:		
//  None
//
// Output:
//  FALSE - as per TSE requirement, that no password was entered
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
BOOLEAN FastBootConInAvailHook(VOID)
{
//	    EFI_STATUS Status;
//	    UINTN Size = sizeof(SETUP_DATA);
//	    static EFI_GUID SetupVariableGuid = SETUP_GUID;
//	    SETUP_DATA SetupData;
//	
//		Status = gRT->GetVariable(L"Setup", &SetupVariableGuid, NULL, &Size, &SetupData);
//		if (EFI_ERROR(Status) || SetupData.FastBoot == 0 || ALLOW_CHECKING_PASSWORD) 
//	        return ProcessConInAvailability();

	if(gFastBootPolicy->FastBootEnable == 0 || gFastBootPolicy->CheckPassword == 1) 
        return ProcessConInAvailability();

#if SETUP_PRINT_ENTER_SETUP_MSG 
{
        CHAR16 *text = NULL;
        text = HiiGetString( gHiiHandle, STRING_TOKEN(STR_DEL_ENTER_SETUP) );
        if ( text != NULL )
            PostManagerDisplayPostMessage(text);
        gBS->FreePool(text);
}
#endif

    return FALSE;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   FastBootBbsBootHook
//
// Description: Function that will be called instead of generic TSE callback
//              on BBS popup boot path
//
// Input:		
//  None
//
// Output:
//  None
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID FastBootBbsBootHook(VOID)
{
    static EFI_GUID FastBootVariableGuid = FAST_BOOT_VARIABLE_GUID;
    EFI_STATUS Status;
    UINT32     BbsPopupCalled = 0x55aa55aa;
    Status = gRT->SetVariable(L"BbsPopupCalled", 
                              &FastBootVariableGuid, 
                              EFI_VARIABLE_BOOTSERVICE_ACCESS,
                              sizeof(BbsPopupCalled),
                              &BbsPopupCalled);
    BbsBoot();
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   FastBootLaunch
//
// Description: Function that will be called instead of generic TSE callback
//              on fast boot path
//
// Input:		
//  None
//
// Output:
//  None
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
#if OVERRIDE_FastBootLaunch
EFI_STATUS FastBootLaunch()
{
	EFI_STATUS Status = EFI_UNSUPPORTED;
	AMI_FAST_BOOT_PROTOCOL * FastBootProtocol = NULL;

	// do the Fast Boot
	if (!EFI_ERROR(gBS->LocateProtocol(&AmiFastBootProtocolGuid, NULL, &FastBootProtocol)))
		Status = FastBootProtocol->Launch();

	// If gFastBootProtocolGuid protocol not found or FastBoot Failed. return
	return Status;
}
#endif
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2010, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************