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
|
/** @file
MeFwDowngrade driver
@copyright
Copyright (c) 2010 - 2012 Intel Corporation. All rights
reserved This software and associated documentation (if any)
is furnished under a license and may only be used or copied in
accordance with the terms of the license. Except as permitted
by such license, no part of this software or documentation may
be reproduced, stored in a retrieval system, or transmitted in
any form or by any means without the express written consent
of Intel Corporation.
This file contains an 'Intel Peripheral Driver' and uniquely
identified as "Intel Reference Module" and is
licensed for Intel CPUs and chipsets under the terms of your
license agreement with Intel or your vendor. This file may
be modified by the user, subject to additional terms of the
license agreement
**/
//
// External include files do NOT need to be explicitly specified in real EDKII
// environment
//
#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000)
#include "EdkIIGlueDxe.h"
#include "MeLib.h"
#include "MeAccess.h"
#include "AmtLib.h"
#include "HeciRegs.h"
#include EFI_GUID_DEFINITION (MePlatformReadyToBoot)
#endif
#define ERROR_HANDLING_DELAY 7000000 ///< show warning msg and stay for 7 seconds.
#define FW_MSG_DELAY 1000 ///< show warning msg and stay for 1 milisecond.
#define FW_MSG_DELAY_TIMEOUT 10
UINT8 HeciHmrfpoLockResult, HeciHmrfpoEnableResult;
VOID
EFIAPI
MeFwDowngradeMsgEvent (
IN EFI_EVENT Event,
IN VOID *Context
)
/**
Tell User that we failed to lock/unlock the flash - Do this after we have graphics initialized
@param[in] Event The event that triggered this notification function
@param[in] Context Pointer to the notification functions context
@retval None
**/
{
if (HeciHmrfpoLockResult != HMRFPO_LOCK_SUCCESS) {
MeReportError (MSG_HMRFPO_LOCK_FAILURE);
}
if (HeciHmrfpoEnableResult != HMRFPO_ENABLE_SUCCESS) {
MeReportError (MSG_HMRFPO_UNLOCK_FAILURE);
}
gBS->CloseEvent (Event);
return;
}
VOID
EFIAPI
MeHmrfpoDisableEvent (
EFI_EVENT Event,
VOID *Context
)
/**
Send the HMRFPO_DISABLE MEI message.
@param[in] Event The event that triggered this notification function
@param[in] Context Pointer to the notification functions context
@retval None
**/
{
UINT32 FWstatus;
UINT8 WriteValue;
UINT8 StallCount;
FWstatus = 0;
WriteValue = 0;
StallCount = 0;
DEBUG ((EFI_D_ERROR, "(B3) Me FW Downgrade - Send the HMRFPO_DISABLE MEI message\n"));
WriteValue = HeciPciRead8 (R_GEN_STS + 3);
WriteValue = WriteValue & BRNGUP_HMRFPO_DISABLE_CMD_MASK;
WriteValue = WriteValue | BRNGUP_HMRFPO_DISABLE_CMD;
DEBUG ((EFI_D_ERROR, "Me FW Downgrade Writing %x to register %x of PCI space\n", WriteValue, (R_GEN_STS + 3)));
///
/// Set the highest Byte of General Status Register (Bits 28-31)
///
HeciPciWrite8 (R_GEN_STS + 3, WriteValue);
FWstatus = HeciPciRead32 (R_FWSTATE);
while
(
((FWstatus & BRNGUP_HMRFPO_DISABLE_OVR_MASK) != BRNGUP_HMRFPO_DISABLE_OVR_RSP) &&
(StallCount < FW_MSG_DELAY_TIMEOUT)
) {
DEBUG ((EFI_D_ERROR, "Me FW Downgrade - ME HMRFPO Disable Status = 0x%x\n", FWstatus));
FWstatus = HeciPciRead32 (R_FWSTATE);
gBS->Stall (FW_MSG_DELAY);
StallCount = StallCount + 1;
}
if ((FWstatus & BRNGUP_HMRFPO_DISABLE_OVR_MASK) == BRNGUP_HMRFPO_DISABLE_OVR_RSP) {
DEBUG ((EFI_D_ERROR, "Me FW Downgrade Disable Msg Received Successfully\n"));
} else {
DEBUG ((EFI_D_ERROR, "Me FW Downgrade Disable Msg ACK not Received\n"));
}
///
/// Hide ME devices so we don't get a yellow bang in OS with disabled devices
///
DisableAllMEDevices ();
gBS->CloseEvent (Event);
return;
}
/**
Entry point for the MeFwDowngrade driver
@param[in] ImageHandle Standard entry point parameter.
@param[in] SystemTable Standard entry point parameter.
@exception EFI_UNSUPPORTED ME policy library initization failure.
@retval Status code returned by CreateEventEx.
**/
EFI_STATUS
MeFwDowngradeEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_EVENT MeFwDowngradeEvent;
EFI_HECI_PROTOCOL *Heci;
UINT32 MeMode;
UINT32 MeStatus;
UINT64 Nonce;
UINT32 FactoryDefaultBase;
UINT32 FactoryDefaultLimit;
HECI_FWS_REGISTER MeFirmwareStatus;
MeFirmwareStatus.ul = HeciPciRead32 (R_FWSTATE);
Status = gBS->LocateProtocol (
&gEfiHeciProtocolGuid,
NULL,
(VOID **) &Heci
);
ASSERT_EFI_ERROR (Status);
Status = Heci->GetMeMode (&MeMode);
ASSERT_EFI_ERROR (Status);
Status = Heci->GetMeStatus (&MeStatus);
ASSERT_EFI_ERROR (Status);
///
/// (B1) Whcih mode ?
///
if (MeMode == ME_MODE_NORMAL) {
///
/// (A2) Intel Me image re-flash is requested?
///
if (MeFwDowngradeSupported ()) {
///
/// (A4)(A5) The BIOS sends the HMRFPO ENABLE MEI message and wiat for response.
///
HeciHmrfpoEnableResult = HMRFPO_ENABLE_UNKNOWN_FAILURE;
Status = HeciHmrfpoEnable (0, &HeciHmrfpoEnableResult);
if (Status == EFI_SUCCESS && HeciHmrfpoEnableResult == HMRFPO_ENABLE_SUCCESS) {
///
/// (A6) The BIOS sends the GLOBAL RESET MEI message
///
DEBUG ((EFI_D_ERROR, "Me FW Downgrade !!- Step A6\n"));
HeciSendCbmResetRequest (CBM_RR_REQ_ORIGIN_BIOS_POST, CBM_HRR_GLOBAL_RESET);
EFI_DEADLOOP ();
}
///
/// (A8) Error Handling, HeciHmrfpoEnable include error handling.
///
DEBUG (
(
EFI_D_ERROR, "Me FW Downgrade Error !!- Step A8, the Status is %r, The result is %x\n", Status,
HeciHmrfpoEnableResult
)
);
IoWrite8 (0x80, 0xA8);
} else {
///
/// (A7) The BIOS sends the HMRFPO Lock MEI message and continues the normal boot
///
HeciHmrfpoLockResult = HMRFPO_LOCK_SUCCESS;
///
/// The ME firmware will ignore the HMRFPO LOCK command if ME is in ME manufacturing mode
///
if ((MeFirmwareStatus.r.ManufacturingMode == 0) &&
(
(ME_STATUS_ME_STATE_ONLY (MeStatus) == ME_IN_RECOVERY_MODE) ||
(ME_STATUS_ME_STATE_ONLY (MeStatus) == ME_READY)
)
) {
DEBUG (
(
EFI_D_ERROR,
"(A7) Me FW Downgrade - The BIOS sends the HMRFPO Lock MEI message and continues the normal boot\n"
)
);
FactoryDefaultBase = 0;
FactoryDefaultLimit = 0;
Status = HeciHmrfpoLock (&Nonce, &FactoryDefaultBase, &FactoryDefaultLimit, &HeciHmrfpoLockResult);
if (Status != EFI_SUCCESS) {
HeciHmrfpoLockResult = HMRFPO_LOCK_FAILURE;
}
}
}
Status = gBS->CreateEventEx (
EFI_EVENT_NOTIFY_SIGNAL,
EFI_TPL_NOTIFY,
MeFwDowngradeMsgEvent,
(VOID *) &ImageHandle,
&gMePlatformReadyToBootGuid,
&MeFwDowngradeEvent
);
}
///
/// (B3) Create an event that will call the HMRFPO_DISABLE
///
if ((MeFirmwareStatus.r.MeOperationMode == ME_OPERATION_MODE_SECOVR_HECI_MSG) &&
(ME_STATUS_ME_STATE_ONLY (MeStatus) == ME_READY)
) {
Status = gBS->CreateEventEx (
EFI_EVENT_NOTIFY_SIGNAL,
EFI_TPL_NOTIFY,
MeHmrfpoDisableEvent,
(VOID *) &ImageHandle,
&gMePlatformReadyToBootGuid,
&MeFwDowngradeEvent
);
}
return Status;
}
|