summaryrefslogtreecommitdiff
path: root/Core/EM/CmosManager/CmosManagerPei.c
blob: 3cc94583d9a4548cc2792e1b5d02f0c0a002cc0e (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
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2009, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************

//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/CMOS Manager/CMOS PEI/CmosManagerPei.c 17    6/15/10 2:23p Michaela $
//
// $Revision: 17 $
//
// $Date: 6/15/10 2:23p $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/CMOS Manager/CMOS PEI/CmosManagerPei.c $
// 
// 17    6/15/10 2:23p Michaela
// 
// 16    3/05/10 4:53p Michaela
// 
// 15    12/04/09 7:30p Michaela
// 
// 14    12/03/09 6:19p Michaela
// 1. CMOS_BSP_IS_EXECUTING status bit 
//    is used instead of gIsBsp
// 
// 2. Loading of Optimal Defaults on bad checksum
//    is done earlier by default and is enabled/disabled
//    by CMOS_RECOVER_IN_PEI SDL token.
//    
//    Note: the bad checksum bit is not cleared until DXE.
//    
// 3. The CMOS_USE_OPTIMAL_DEFAULTS enum is replaced with
//    CMOS_OPTIMAL_DEFAULTS_ON.
// 
// 13    11/10/09 9:13p Michaela
// 
// 12    7/29/09 9:56a Michaela
// updates Aptio Enhancement EIP 22205
// (no code changes)
// 
// 11    6/15/09 5:10p Michaela
// 
// 10    6/02/09 4:38p Michaela
// 
// 9     6/02/09 3:26p Michaela
// For label: 4.6.3_CMOSMGR_11
// 
// 8     3/11/09 3:37p Michaela
// 
// 7     11/25/08 3:15p Michaela
// Updates for Label 4.6.3_CMOSMGR_08
// - Assembly macro fixes
// - Added assembly macros
// - Moved loading defaults into DXE phase
// - Updated help file example
// 
// 6     11/17/08 4:03p Michaela
// --Removed development degugging code
// 
// 5     11/07/08 5:14p Michaela
// Updated to make CMOS manager available in all phases 
// of the boot process:
// 
// A CMOS API Pointer is maintained in CMOS and accessible
// via provided macros in C and assembly source.
// 
// 4     3/07/08 4:06p Michaela
// Label 4.6.3_CMOSMGR_05 fixes:
// -- write errors to Optimal Defaults buffer before memory detection
// -- CMOS Token table corruption when name strings are disabled
// 
// 3     2/29/08 9:33p Michaela
// - Added recovery path policy
// - fixed other minor bugs
// 
// 2     2/26/08 12:52p Michaela
// Added/modified Helpbuilder headers
// 
// 1     2/22/08 2:29p Michaela
// 
// 1     2/04/08 6:00p MichaelA
// Created
// 
//**********************************************************************

//<AMI_FHDR_START>
//---------------------------------------------------------------------------
//
// Name:    CmosManagerPei.c
//
// Description:     Contains the routines that constitute the CMOS manager's
//                  PEI phase entry.
//
//---------------------------------------------------------------------------
//<AMI_FHDR_END>

#include <Token.h>
#include "CmosManagerPei.h"

#define LOCATE_READ_ONLY_VARIABLE_PPI(Status, InterfacePtr) { \
    EFI_GUID Guid = EFI_PEI_READ_ONLY_VARIABLE_PPI_GUID; \
    Status = (*PeiServices)->LocatePpi( PeiServices, &Guid, \
        0, NULL, &InterfacePtr); }
        

//---------------------------------------------------------------------------
//  PEI entry point function
//
//<AMI_PHDR_START>
//---------------------------------------------------------------------------
//
// Procedure: CmosManagerPeiEntry
//
// Description:
//      This function is the main PEI phase entry point for the CMOS
//      manager module.
//
// Input:
//      IN EFI_FFS_FILE_HEADER *FfsHeader
//                  -- FFS file header pointer
//      IN EFI_PEI_SERVICES **PeiServices
//                  -- PEI Services table pointer
//
// Output:
//      EFI_STATUS (Return Value)
//                  = EFI_SUCCESS if successful
//                  = or other valid EFI error code
//
// Notes:
//      Execution Sequence:
//                  1)  Initialize CMOS Manager interface
//                  2)  Load default values into CMOS registers if
//                      this is the first boot.
//                  3)  Configure usage of the Optimal Defaults table if
//                      the battery or checksum is bad.
//                  4)  Update the CMOS-based API/PPI pointer.
//                  5)  Install the EFI_CMOS_ACCESS_INTERFACE PPI
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS CmosManagerPeiEntry (
    IN EFI_FFS_FILE_HEADER       *FfsHeader,
    IN EFI_PEI_SERVICES          **PeiServices )
{
    EFI_STATUS                  Status;
    EFI_CMOS_MANAGER_INTERFACE  *Mgr;
    UINT8                       CmosValue = 0;


    CMOS_TRACE_FULL((CMOS_TRACE_ALWAYS, "CmosManagerPeiEntry Entry\n" ));

    //-----------------------------------------------------------------------
    // Initialize the manager interface and, at this point, only check for  
    // interface initialization errors.
    //-----------------------------------------------------------------------

    Mgr = NewCmosManagerInterface(PeiServices);
    if ( Mgr == NULL || !Mgr->CheckStatus(Mgr, CMOS_VALID_INTERFACE) )
        return  Status = EFI_UNSUPPORTED;
    if ( Mgr->CheckStatus( Mgr, CMOS_INTERFACE_ALREADY_INSTALLED) )
        return  Status = EFI_SUCCESS;
    
    //-----------------------------------------------------------------------
    // Handle specific internally-reported conditions.
    //-----------------------------------------------------------------------

    if (    Mgr->CheckStatus(Mgr, CMOS_IS_USABLE )
         && Mgr->CheckStatus(Mgr, CMOS_BSP_IS_EXECUTING ) )
    {
        // Load optimal defaults on first boot after programming
        // boot device.

        if  (    Mgr->CheckStatus(Mgr, CMOS_FIRST_BOOT_DETECTED )
              && Mgr->CheckStatus(Mgr, CMOS_COLD_BOOT_DETECTED )  )
        {
            CMOS_TRACE((CMOS_TRACE_ALWAYS, "First boot detected ...\n" ));
            Mgr->LoadOptimalDefaults(Mgr);
            CMOS_TRACE((CMOS_TRACE_ALWAYS, "...Defaults loaded\n" ));
        }

        // Save CMOS-based PPI pointer

        CMOS_TRACE_FULL((CMOS_TRACE_ALWAYS, "Saving PPI pointer to CMOS\n" ));
        Mgr->SaveApiPointerToCmos(Mgr, NULL);
    }
    else {
        CMOS_TRACE_FULL((CMOS_TRACE_ALWAYS, "Defaults were not loaded\n" ));
    }

    //-----------------------------------------------------------------------
    // If the CMOS hardware is not usable, configure CMOS Manager to use the
    // read/write Optimal Defaults buffer for Managed Region access. 
    //-----------------------------------------------------------------------

    if ( Mgr->CheckAnyStatus( Mgr, CMOS_BAD_CHECKSUM | CMOS_BAD_BATTERY ) ){
        if ( Mgr->CheckStatus( Mgr, CMOS_BAD_CHECKSUM) )
            CMOS_TRACE((CMOS_TRACE_ALWAYS, "Bad Checksum:\n" ));

        if ( Mgr->CheckStatus( Mgr, CMOS_BAD_BATTERY) )
            CMOS_TRACE((CMOS_TRACE_ALWAYS, "Bad Battery:\n" ));

        if (    Mgr->CheckStatus(Mgr, CMOS_IS_USABLE )
             && Mgr->CheckStatus(Mgr, CMOS_RECOVER_IN_PEI ) )
        {
            CMOS_TRACE((CMOS_TRACE_ALWAYS, "  Loading Optimal Defaults\n"));
            Mgr->LoadOptimalDefaults( Mgr );
            Mgr->ConfigureManager( Mgr, CMOS_OPTIMAL_DEFAULTS_OFF );
            CMOS_TRACE((CMOS_TRACE_ALWAYS, "...Defaults loaded\n" ));
        }
        else {
            CMOS_TRACE((CMOS_TRACE_ALWAYS, "  Using Optimal Defaults.\n"));
            Mgr->ConfigureManager( Mgr, CMOS_OPTIMAL_DEFAULTS_ON );
        }

    }    

   
    //-----------------------------------------------------------------------
    // Install the CMOS Access PPI
    //-----------------------------------------------------------------------

    CMOS_TRACE_FULL((CMOS_TRACE_ALWAYS, "Installing CMOS Access PPI\n" ));
    Mgr->InstallAccessInterface(Mgr);
    if ( !Mgr->CheckStatus(Mgr, CMOS_VALID_MANAGER ) ){
        CMOS_TRACE((CMOS_TRACE_ALWAYS, 
            "Invalid interface ... Access PPI not installed\n" ));
        return Status = EFI_UNSUPPORTED;
    }


    CMOS_TRACE_FULL((CMOS_TRACE_ALWAYS, 
        "CmosManagerPeiEntry successful exit\n" ));

    return Status = EFI_SUCCESS;
}
    
    



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