summaryrefslogtreecommitdiff
path: root/Core/EM/OFBD/DEFCFG/DefCfg.c
blob: 5923a0bcecb33326ade99c44027139ed3684c043 (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
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2013, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************

//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/OFBD/DEFCFG/DefCfg.c 9     8/16/13 3:13a Terrylin $
//
// $Revision: 9 $
//
// $Date: 8/16/13 3:13a $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/OFBD/DEFCFG/DefCfg.c $
// 
// 9     8/16/13 3:13a Terrylin
// [Description]  	Correct the description error.
// 
// 8     8/07/13 11:21p Terrylin
// [Description]  	Add more description.
// 
// 7     7/31/13 4:49a Terrylin
// [TAG]  		EIP125898
// [Category]  	New Feature
// [Description]  	Add the AFU's /Kn and /Ln two commands status control.
// 
// 6     8/06/12 7:00a Terrylin
// [TAG]  		EIP96286
// [Category]  	Improvement
// [Description]  	Add the template codes for SMBIOS module DMI data
// preserve support.
// [Files]  		DefCfg.sdl
// DefCfg.c
// 
// 5     2/22/12 4:37a Terrylin
// Add the GAN command support sample
// 
// 4     3/16/11 10:37p Terrylin
// [TAG]  		EIP51285
// [Category]  	Improvement
// [Description]  	Fill the description for user more clearly.
// [Files]  		DefCfg.mak
// DefCfg.h
// DefCfg.c
// 
// 3     12/17/10 3:21a Terrylin
// Fix sample code is wrong problem.
// 
// 2     6/07/10 11:22p Terrylin
// Fix sample code is wrong problem.
// 
// 1     5/06/10 2:22a Lawrencechang
// Initial check-in.
// 
//**********************************************************************
//<AMI_FHDR_START>
//
// Name:	DefCfg.c
//
// Description:
// OFBD Default Command Configuration provides BIOS an oppertunity to override end user issued command in AFU.
//
// For example, BIOS could disable /k command even user issued it in AFU, or automatically enable /b when /p
// is issued.
//
// For AFU¡¦s "/Ln" and "/Kn" two commands parameter identify. That AFU will replace the OFBD_EXT_TBL_END data 
// from 0xFFFF55AA to OFBD_TC_51_DC_EXT_STRUCT. Therefore, BIOS can through the "ddIndexCfg" flag to identify
// who is this command structure. (The AFU version 3.05.1 or later supports.)
//
// Please reference OFBDDEFCFGHandle for more details.
//
//<AMI_FHDR_END>
//**********************************************************************
#include "Efi.h"
#include "token.h"
#include <AmiLib.h>
#include <AmiDxeLib.h>
#include "DefCfg.h"
#include "..\OFBD.h"

//#define CONVERT_TO_STRING(a) #a
#define STR(a) CONVERT_TO_STRING(a)

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	OFBDDEFCFGHandle
//
// Description:	OFBD Default Command Configuration Handle
//
// Input:
//      IN OUT OFBD_HDR *pOFBDHdr
// Output:
//      EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
OFBDDEFCFGHandle( 
    IN OUT OFBD_HDR *pOFBDHdr)
{
    EFI_STATUS Status = EFI_SUCCESS;

	UINT8 *pOFBDTblEnd;
	OFBD_TC_51_DC_STRUCT *DCStructPtr;
	OFBD_TC_51_DC_EXT_STRUCT *DCExtStructPtr;
	UINT32 ExtAddr;
	
	pOFBDTblEnd = (UINT8 *)((UINT8 *)pOFBDHdr + (pOFBDHdr->OFBD_Size));
	DCStructPtr = (OFBD_TC_51_DC_STRUCT *)((UINT8 *)pOFBDHdr + pOFBDHdr->OFBD_HDR_SIZE + sizeof(OFBD_EXT_HDR)); 
	DCExtStructPtr = (OFBD_TC_51_DC_EXT_STRUCT *)((UINT8 *)pOFBDHdr + (pOFBDHdr->OFBD_Size) - sizeof(OFBD_END));
	ExtAddr = *(UINT32 *)((UINT8 *)pOFBDTblEnd - sizeof(OFBD_END));
	if (ExtAddr == OFBD_EXT_TBL_END)
	    DCExtStructPtr = NULL;
	
#if SMBIOS_DMIEDIT_DATA_LOC == 2

	if ((DCStructPtr->ddRetSts & OFBD_TC_CFG_N) && (DCStructPtr->ddRetSts & OFBD_TC_CFG_R) && (DCStructPtr->ddRetSts & OFBD_TC_CFG_CAPSULE))
    {
        EFI_GUID    gEfiSmbiosNvramGuid = {0x4b3082a3, 0x80c6, 0x4d7e, { 0x9c, 0xd0, 0x58, 0x39, 0x17, 0x26, 0x5d, 0xf1 }};
        CHAR16      *PreserveSmbiosNvramVar = L"PreserveSmbiosNvramVar";
		UINTN 		Size = sizeof (UINT8);
        UINT32      PreserveSmbiosNvram;

		// Set PreserveSmbiosNvram
		pRS->SetVariable (
			PreserveSmbiosNvramVar,
			&gEfiSmbiosNvramGuid,
			EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
			Size,
			&PreserveSmbiosNvram
			);
	}

#endif
    
#if DEF_CFG_SAMPLE_TEST
    //
	// OEM add
	//
	
	// Sample : always cancel /K command
	if (DCStructPtr->ddRetSts & OFBD_TC_CFG_K)
	{
		DCStructPtr->ddExtCfg |= OFBD_TC_CFG_K;
	}
	
	// Sample : add new /B command when /P has issued
	if (DCStructPtr->ddRetSts & OFBD_TC_CFG_P)
	{
		DCStructPtr->ddRetSts |= OFBD_TC_CFG_B;
	}

    // Sample : For GAN command 
    // If ddRetSts equals to "0xFFFFFFFF", this means BIOS supply "/GAN" command.
	if (DCStructPtr->ddRetSts & OFBD_TC_CFG_GAN)
	{
		DCStructPtr->ddRetSts = 0xFFFFFFFF;
	}
		
	// Sample : For /Ln or /Kn command status setting
	if (DCExtStructPtr)
    {
        OFBD_TC_51_DC_EXT_STRUCT *NStructPtr = DCExtStructPtr;
        
        do
        {
            // Check current struct is Ln command or not
            if (NStructPtr->ddIndexCfg == OFBD_TC_CFG_LN)
            {
                // Sample : add new /L1 command when /L0 command is issued
                if (NStructPtr->ddExtCfg & BIT00)
                {
                    NStructPtr->ddExtCfg |= BIT01;
                }
            }
            
            // Check current struct is Kn command or not
            if (NStructPtr->ddIndexCfg == OFBD_TC_CFG_KN)
            {
                // Sample : always cancel /K0 command
                if (NStructPtr->ddExtCfg & BIT00)
                {
                    NStructPtr->ddIgnCfg |= BIT00;
                }
            }
            // Ponit to next structure
            NStructPtr++;
            ExtAddr = *(UINT32 *)NStructPtr;
        }while(ExtAddr && ExtAddr != 0xFFFFFFFF);
    }
#endif

    return(Status);
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	DEFCFGEntry
//
// Description:	OFBD Default Command Configuration Entry Point
//
// Input:
//      IN VOID             *Buffer
//      IN OUT UINT8        *pOFBDDataHandled
// Output:
//      VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID DEFCFGEntry (
    IN VOID             *Buffer,
    IN OUT UINT8        *pOFBDDataHandled )
{
	OFBD_HDR *pOFBDHdr;
	OFBD_EXT_HDR *pOFBDExtHdr; 
	VOID *pOFBDTblEnd;
	OFBD_TC_51_DC_STRUCT *DCStructPtr;  

	if(*pOFBDDataHandled == 0)
	{
		pOFBDHdr = (OFBD_HDR *)Buffer;
		pOFBDExtHdr = (OFBD_EXT_HDR *)((UINT8 *)Buffer + (pOFBDHdr->OFBD_HDR_SIZE));
		DCStructPtr = (OFBD_TC_51_DC_STRUCT *)((UINT8 *)pOFBDExtHdr + sizeof(OFBD_EXT_HDR)); 
		pOFBDTblEnd = (VOID *)((UINT8 *)Buffer + (pOFBDHdr->OFBD_Size));    
		
		if(pOFBDHdr->OFBD_FS & OFBD_FS_CFG)
		{   
			//Check Type Code ID
			if(pOFBDExtHdr->TypeCodeID == OFBD_EXT_TC_AFUDEFCFG)
			{  
				if(OFBDDEFCFGHandle(pOFBDHdr) == EFI_SUCCESS)
				{
					//OEM Default Command Configuration Handled.
					*pOFBDDataHandled = 0xFF;      
					return;
				}
			} 
			//Error occured
			*pOFBDDataHandled = 0xFE;          
			return;
		}  
	}

    return;
}

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