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

//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/SMBIOS/SmbiosPeim/SmbiosPei.c 1     5/27/14 1:44p Davidd $
//
// $Revision: 1 $
//
// $Date: 5/27/14 1:44p $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/SMBIOS/SmbiosPeim/SmbiosPei.c $
// 
// 1     5/27/14 1:44p Davidd
// [TAG]  		EIP103526
// [Category]  	Improvement
// [Files]  		SmbiosPeim.cif
// SmbiosPeim.sdl
// SmbiosPeim.mak
// SmbiosPeim.dxs
// SmbiosPei.c
// 
// 1     4/29/14 4:44p Davidd
// [TAG]  		EIP103526
// [Category]  	Improvement
// [Description]  	We should update Wake-up Type in SMBIOS type 1
// dynamically
// [Files]  		Core\EM\SMBios\SmbiosPeim\SmbiosPeim.cif
// Core\EM\SMBios\SmbiosPeim\SmbiosPeim.sdl
// Core\EM\SMBios\SmbiosPeim\SmbiosPeim.mak
// Core\EM\SMBios\SmbiosPeim\SmbiosPeim.dxs
// Core\EM\SMBios\SmbiosPeim\SmbiosPei.c
// 
//**********************************************************************
//<AMI_FHDR_START>
//
// Name:  SmbiosPei.c
//
// Description:	
//
//<AMI_FHDR_END>
//**********************************************************************

#include <AmiPeiLib.h>
#include <Ppi\ReadOnlyVariable2.h>
#include "Core\Ppi\MemoryDiscovered.h"

extern VOID		OemRuntimeShadowRamWrite(IN BOOLEAN Enable);
extern UINT8	getWakeupTypeForSmbios(VOID);

EFI_STATUS
SmbiosAfterInitMemory(
  IN EFI_PEI_SERVICES           **PeiServices,
  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,
  IN VOID                       *NullPpi
);

static EFI_GUID gPeiPermanentMemInstalledPpiGuid = PEI_PERMANENT_MEMORY_INSTALLED_PPI_GUID;

static EFI_PEI_NOTIFY_DESCRIPTOR SmbiosPeiNotify[] =
{
    {
        EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
        &gPeiPermanentMemInstalledPpiGuid,
        SmbiosAfterInitMemory
    }
};

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure: UpdateSmbiosWakeupType
//
// Description: Detect and update SMBIOS Type 1 structure "Wake-up Type"
//              data field
//
// Input:IN EFI_PEI_SERVICES  **PeiServices,
//
// Output: Updated SMBIOS Type 1 "Wake-up Type"
//
// Notes:
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID
UpdateSmbiosWakeupType(
    IN EFI_PEI_SERVICES **PeiServices
)
{
    EFI_STATUS                          Status;
    EFI_PEI_READ_ONLY_VARIABLE2_PPI     *ReadOnlyVariable;
    EFI_GUID                            EfiPeiReadOnlyVariablePpiGuid = \
                                        {0x2ab86ef5, 0xecb5, 0x4134, {0xb5, 0x56, 0x38, 0x54, 0xca, 0x1f, 0xe1, 0xb4}};
    EFI_GUID                            EfiSmbiosNvramGuid = \
                                        {0x4b3082a3, 0x80c6, 0x4d7e, {0x9c, 0xd0, 0x58, 0x39, 0x17, 0x26, 0x5d, 0xf1}};
    UINTN                               DataSize = 4;
    UINT32                              WakeupTypePtr;

    Status = (*PeiServices)->LocatePpi(
                                        PeiServices,
                                        &EfiPeiReadOnlyVariablePpiGuid,
                                        0,
                                        NULL,
                                        &ReadOnlyVariable);
    ASSERT_PEI_ERROR(PeiServices, Status);

    if (Status == EFI_SUCCESS){
        Status = ReadOnlyVariable->GetVariable(
                                        ReadOnlyVariable,
                                        L"WakeUpType",
                                        &EfiSmbiosNvramGuid,
                                        NULL,
                                        &DataSize,
                                        &WakeupTypePtr);
        if (Status == EFI_SUCCESS) {
            if (WakeupTypePtr > 0xf0000) {
                *(UINT8*)WakeupTypePtr = getWakeupTypeForSmbios();
            }
            else {
                OemRuntimeShadowRamWrite(TRUE);
                *(UINT8*)WakeupTypePtr = getWakeupTypeForSmbios();
                OemRuntimeShadowRamWrite(FALSE);
            }
        }
    }
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure: SmbiosAfterInitMemory
//
// Description:
//
// Input: IN EFI_PEI_SERVICES           **PeiServices,
//        IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,
//        IN VOID                       *NullPpi
//
// Output:
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
SmbiosAfterInitMemory(
  IN EFI_PEI_SERVICES           **PeiServices,
  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,
  IN VOID                       *NullPpi
)
{
    EFI_STATUS Status;
    EFI_BOOT_MODE BootMode;

    // Determine boot mode
    Status = (*PeiServices)->GetBootMode(PeiServices, &BootMode);
    ASSERT_PEI_ERROR(PeiServices, Status);

    if (BootMode == BOOT_ON_S3_RESUME) {
        UpdateSmbiosWakeupType(PeiServices);
    }

    return EFI_SUCCESS;
}

EFI_STATUS
SmbiosPeiEntryPoint(
	IN EFI_FFS_FILE_HEADER       *FfsHeader,
  	IN EFI_PEI_SERVICES          **PeiServices
)
{
    EFI_STATUS Status;

    // Set the Smbios Notify PPI
    Status = (*PeiServices)->NotifyPpi(PeiServices, SmbiosPeiNotify);
    ASSERT_PEI_ERROR(PeiServices, Status);

	return EFI_SUCCESS;
}

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