summaryrefslogtreecommitdiff
path: root/EDK/MiniSetup/TseLite/TseLiteCommon.c
blob: ac72ff3cdec53e59df45305d33f92afa3e1bf60e (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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
//**                                                             **//
//**         (C)Copyright 2012, American Megatrends, Inc.        **//
//**                                                             **//
//**                     All Rights Reserved.                    **//
//**                                                             **//
//**   5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093  **//
//**                                                             **//
//**                     Phone (770)-246-8600                    **//
//**                                                             **//
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseLite/TseLiteCommon.c $
//
// $Author: Premkumara $
//
// $Revision: 16 $
//
// $Date: 8/28/14 9:11a $
//
//*****************************************************************//
//*****************************************************************//
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseLite/TseLiteCommon.c $
// 
// 16    8/28/14 9:11a Premkumara
// [TAG] 		EIP168489
// [Category] 	Bug Fix
// [Severity:]		Normal
// [Symptom:] 	System will display blue screen after use OEM command to
// boot to BIOS Setup Utility from Built-in EFI Shell
// [Files] 		TseliteCommon.c
// 
// 15    2/11/14 8:47p Arunsb
// [TAG]	EIP148693
// [Category]	Bug Fix
// [Severity:]	Important
// [Symptom:]	Slowness in shell performance
// [Root Cause]	Memory fragmentation
// [Solution]	Controlled the TSE destructor with token from sdl file
// [Files]	amitse.sdl, tselitecommon.c
// 
// 14    6/10/13 10:03a Arunsb
// gRefreshIdCount made as 0 bcoz exiting from setup and coming back wont
// reinit it
// 
// 13    4/18/13 9:31a Arunsb
// Function moved to avoid build error in 2.0
// 
// 12    4/15/13 5:40a Arunsb
// gRefreshIdInfo check added
// 
// 11    10/18/12 6:02a Arunsb
// Updated for 2.16.1235 QA submission
// 
// 9     10/10/12 12:38p Arunsb
// Synched the source for v2.16.1232, backup with Aptio
// 
// 9     9/14/12 12:59p Madhans
// [TAG]  		EIP101218
// [Category]  	Bug Fix
// [Severity]  	Critical
// [Symptom]  	If Sendform is called more than once from DHP
// (DriverHealthprotocol Module). It does not enter.
// [RootCause]  	SendForm called before postmanagerhandsake was not
// cleaned gApp correctly.
// [Solution]  	Fix to do the cleanup
// [Files]  		tselitecommon.c
// 
// 8     5/28/12 7:29a Rajashakerg
// [TAG]  		EIP85564
// [Category]  	Improvement
// [Description]  	UefiHiiTestPrintLength function needs optimization
// [Files]  		TseLiteCommon.c, hiistring21.c
// 
// 7     4/27/12 7:28a Arunsb
// [TAG]  		EIP88449 
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	SUT hangs when "Exit Without Saving" prompt is select as
// 'yes' in setup.
// [RootCause]  	gVariablelist freed before calling callback
// [Solution]  	gVariablelist freed after calling callback
// [Files]  		TseLiteCommon.c
// 
// 6     3/28/11 9:25p Madhans
// [TAG]  		EIP41744 
// [Category]  	Improvement
// [Description]  	SoftKeyBoard Support in TSE. and Support to Work with
// new mouse driver(Label 07).
// [Files]  		HookAnchor.h
// AMITSE.sdl
// CommonHelper.c
// commonoem.c
// commonoem.h
// HookList.c
// HookAnchor.c
// Mouse.c
// minisetupext.c
// postmgmtext.c
// minisetupext.h
// PopupPassword.c
// PopupString.c
// TseLiteCommon.c
// 
// 5     3/21/11 12:46a Rajashakerg
// [TAG]  		EIP53480
// [Category]  	Improvement
// [Description]  	FormBrowser extended actions support
// [Files]  		callback.c, minisetupext.c, minisetupext.h, numeric.c,
// PopupSel.c, PopupString.c, SubMenu.c, TseLiteCommon.c, UefiAction.c,
// Hiicallback.c, TseUefiHii.h, Uefi21Wapper.c, HiiCallback.c
// 
// 4     2/19/10 1:04p Madhans
// Updated for TSE 2.01. Refer Changelog.log for File change history.
// 
// 6     2/19/10 8:19a Mallikarjunanv
// updated year in copyright message
// 
// 5     1/09/10 7:13a Mallikarjunanv
// Updated TSE2.01 Release sources with coding standards
// 
// 4     8/13/09 1:21p Blaines
// EIP #24980 Fix to properly display right area text
// 
// 3     6/23/09 6:53p Blaines
// Coding standard update, 
// Remove spaces from file header to allow proper chm function list
// creation.
// 
// 2     6/12/09 7:44p Presannar
// Initial implementation of coding standards for AMITSE2.0
// 
// 1     6/04/09 8:05p Madhans
// 
// 2     5/07/09 10:36a Madhans
// Changes after Bin module
// 
// 1     4/28/09 11:07p Madhans
// Tse 2.0 Code complete Checkin.
// 
// 1     4/28/09 9:40p Madhans
// Tse 2.0 Code complete Checkin.
// 
// 1     12/18/08 7:59p Madhans
// Intial version of TSE Lite sources
// 
//
//*****************************************************************//
//*****************************************************************//

//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:		TseLiteCommon.c
//
// Description:	This file contains code for the TSE Lite common functions
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>

#include "minisetup.h"


SETUP_PKG		*gSetupPkg;
SCREEN_INFO		*gScreen;
PAGE_LIST		*gToolPages;
PAGE_LIST		*gPages;
CONTROL_INFO	*gToolControlInfo;
CONTROL_INFO	*gControlInfo;
VARIABLE_LIST	*gToolVariables;
VARIABLE_LIST	*gVariables;
HPK_INFO		*gHpkInfo;
GUID_LIST		*gGuidList;
PAGE_ID_LIST	*gPageIdList;
PAGE_ID_LIST	*gToolPageIdList;
PAGE_ID_INFO	*gPageIdInfo;
PAGE_ID_INFO	*gToolPageIdInfo;
FRAME_DATA		*gActiveFrame = NULL;

UINT16	gCheckboxTokens[] =
{
	STRING_TOKEN(STR_CTRL_CHKBOX_DISABLE),
	STRING_TOKEN(STR_CTRL_CHKBOX_ENABLE)
};

UINTN gLabelLeftMargin = 2 ;
UINTN gControlLeftMargin = 24;
UINTN gControlLeftPad = 2 ;
UINTN gControlRightAreaWidth = 27 ;
BOOLEAN	gVariableChanged = FALSE;
BOOLEAN	gResetRequired = FALSE;
UINT32 gStartPage = 0;

APPLICATION_DATA	*gApp = NULL;
UINTN           gHpkInfoLength;
UINT32 GetControlConditionVarId(CONTROL_INFO *control);

extern CHAR8 *GlyphWidthCache;//EIP 85564 : UefiHiiTestPrintLength function needs optimization
extern UINT32 gRefreshIdCount;
extern REFRESH_ID_INFO *gRefreshIdInfo;
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	MiniSetupUIExit
//
// Description:	Freesup UI related resources.
//
// Input:		none
//
// Output:		none
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
BOOLEAN TseDebugDisableApplicationDestructor (VOID);
VOID MiniSetupUIExit(VOID)
{
    EFI_STATUS Status = EFI_SUCCESS;
	UINTN index;

	// Don't do the MiniSetupExit if it is not a first call to PostManagerHandshake.
	if(gPostManagerHandshakeCallIndex>2) //gApp should be preserved when it is not freed.
	{
		// to Let Next call not quit.
		gApp->Quit=FALSE;
		goto Done;
	}
	
	if ( gApp != NULL )
	{
		if (!TseDebugDisableApplicationDestructor ())
		{
			gApplication.Destroy( gApp, TRUE );
		}
		gApp = NULL;

		MouseDestroy();
	}

Done:
    //Close the Event and Free the NotifyContext created for Controls with Refresh Id.
    if(gRefreshIdInfo) {
        for(index = 0; index < gRefreshIdCount; index++) 
        {
            if(gRefreshIdInfo[index].pEvent)//Close the event
            {
	            Status = gBS->CloseEvent(gRefreshIdInfo[index].pEvent);
	            if(Status == EFI_SUCCESS)
                {
		            gRefreshIdInfo[index].pEvent = NULL;
	            }		
            }
            
            MemFreePointer( (VOID **)&gRefreshIdInfo[index].pNotifyContext );
        }
        MemFreePointer( (VOID **)&gRefreshIdInfo );
        gRefreshIdCount = 0;
    }

    UEFICallSetupFormCallBack(AMI_CALLBACK_FORM_CLOSE);//EIP-53480: Calling the Wrapper function with AMI_CALLBACK_FORM_CLOSE action before HiiExit() 
    if ( gVariableList != NULL )
    {
	    for ( index = 0; index < gVariables->VariableCount; index++ )
		    MemFreePointer( (VOID **)&gVariableList[index] );

	    MemFreePointer( (VOID **)&gVariableList );
    }
    //Commented and moved above for EIP88449
    //UEFICallSetupFormCallBack(AMI_CALLBACK_FORM_CLOSE);//EIP-53480: Calling the Wrapper function with AMI_CALLBACK_FORM_CLOSE action before HiiExit() 
    HiiExit( );


    if(GlyphWidthCache) {
        MemFreePointer((VOID **)&GlyphWidthCache);// EIP 85564 :free the memory which was used to store the widths of each possible CHAR16 glyph.
    }

}


//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	GetBootTimeOut
//
// Description:	Timeout value from the variable.
//
// Input:		DefaultValue
//
// Output:		Timeout value
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
UINT16 GetBootTimeOutLocal(UINT16 DefaultValue)
{
	UINT16 *TimeOut=NULL, Value = 0;
	UINTN size = 0;

	// Install boot timeout
	TimeOut = VarGetNvram( VARIABLE_ID_BOOT_TIMEOUT, &size );

	if ( TimeOut != NULL )
	{
		Value = *TimeOut;
	}
	else
	{
		Value = DefaultValue;
		VarSetNvram( VARIABLE_ID_BOOT_TIMEOUT, &Value, sizeof(UINT16) );
	}

	return Value;
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	_GetControlVariable
//
// Description:	Function to get control variable.
//
// Input:		CONTROL_INFO *control
//
// Output:		UINT32
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
UINT32 _GetControlVariable(CONTROL_INFO *control)
{
	return control->ControlVariable;
}

//<AMI_PHDR_START>
//---------------------------------------------------------------------------
// Procedure:   _GetPageInfo
//
// Description: Returns pointer to the PAGE_INFO struct of given PgIndex
//
// Input:	UINT32 PgIndex - Page index
//			PAGE_INFO **PageInfo - Pointer to the page information struct
//
// Output:	EFI_STATUS status - EFI_SUCCESS if successful, else EFI_ERROR
//---------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS _GetPageInfo(UINT32 PgIndex, PAGE_INFO **PageInfo)
{
  EFI_STATUS status = EFI_SUCCESS;

  if((gApplicationData == NULL) || (gPages == NULL))
  {
    status = EFI_NOT_READY;
    goto DONE;
  }

  if(PgIndex > gPages->PageCount)
  {
    status = EFI_INVALID_PARAMETER;
    goto DONE;
  }

  *PageInfo = (PAGE_INFO*)((UINTN)gApplicationData + gPages->PageList[PgIndex]);

DONE:
  return status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:     IsPageModal
//
// Description:   Is this a modal page 
//
// Parameter:     IN  UINT32 PgIndex
//
// Return Value:  BOOLEAN
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
#define ASSERT_ERROR_STATUS(assertion)		if(EFI_ERROR(assertion)) goto DONE
BOOLEAN IsPageModal(UINT32 PgIndex)
{
  EFI_STATUS status = EFI_SUCCESS;
  BOOLEAN isTrue = FALSE;
  PAGE_INFO *pageInfo = NULL;

  status = _GetPageInfo(PgIndex, &pageInfo);
  ASSERT_ERROR_STATUS(status);
  isTrue = pageInfo->PageFlags.PageModal ? TRUE : FALSE;

DONE:
  return isTrue;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure:     GetPageSubTitle
//
// Description:   Get the Page Subtitle String Index
//
// Parameter:     IN  UINTN  PgIndex
//                OUT UINT16 *subtitleToken
//
// Return Value:  EFI_STATUS
//                    EFI_SUCCESS
//                    EFI_NOT_READY
//                    EFI_INVALID_PARAMETER
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS GetPageSubTitle(UINT32 PgIndex, UINT16 *SubtitleToken)
{
  EFI_STATUS status = EFI_SUCCESS;
  PAGE_INFO *pageInfo = NULL;

  status = _GetPageInfo(PgIndex, &pageInfo);
  ASSERT_ERROR_STATUS(status);

  *SubtitleToken = pageInfo->PageSubTitle;

DONE:
  return status;
}
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2012, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**     5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093     **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************