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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
|
//**********************************************************************
//**********************************************************************
//** **
//** (C)Copyright 1985-2009, American Megatrends, Inc. **
//** **
//** All Rights Reserved. **
//** **
//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
//** **
//** Phone: (770)-246-8600 **
//** **
//**********************************************************************
//**********************************************************************
//**********************************************************************
//
// $Header: /Alaska/BIN/Board/OemDxe.c 32 11/01/11 4:29p Artems $
//
// $Revision: 32 $
//
// $Date: 11/01/11 4:29p $
//
//*****************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/Board/OemDxe.c $
//
// 32 11/01/11 4:29p Artems
// EIP 71380: CSM opt-out feature support. Legacy OpROM policy moved into
// CSM opt-out module
//
// 31 7/21/11 8:53a Felixp
// Bug fix in the GOP detection logic introduced by previous check in
// (EIP64103)
//
// 30 7/19/11 4:59p Felixp
// [TAG] EIP64103
// [Category] New Feature
// [Description] Setup control to enable/disable execution of the Legacy
// Option ROM for video devices
// is extended to support "Enable if no GOP on the handle" option.
// [Files] Board.sdl
// Oem.sd
// Oem.uni
// OemDxe.c
//
// 29 7/13/11 2:23p Felixp
// [TAG] EIP64103
// [Category] New Feature
// [Description] Setup control to enable/disable execution of the Legacy
// Option ROM for video devices is implemented.
// [Files] Board.sdl
// Oem.sd
// Oem.uni
// OemDxe.c
//
// 28 3/10/11 5:58a Rajeshms
// [TAG] - EIP 39307
// [Category]- BUG FIX
// [Severity]- Normal
// [Symptom] - Enter DOS no screen when legacy serial redirection enable
// with option rom message display option is set to " Keep current" in
// setup.
// [RootCause] - Actual INT 10h handler was not replaced after dispatching
// option rom. Legacy console redirection driver INT10h was replaced
// instead of actual handler when option rom message display option was
// set to " Keep current".
// [Solution] - Legacy Console redirection is disabled after its handler
// is replaced in INT 10h place by the dummy handler so that actual INT10h
// handler is replaced by Legacy Console redirection driver. To Support
// redirection for ISA oprom's , enable and disable of legacy console
// redirection has been moved to CsmOpRom.c from OemDxe.c.
// [Files] - CsmOpRom.c, OemDxe.c
//
// 27 3/08/11 1:52p Olegi
// [TAG] EIP54455
// [Category] Improvement
// [Description] In some cases signaling the Option ROM execution event
// is not in sync between PreprocessOprom and PostProcessOprom.
// [Files] oemdxe.c
//
// 26 2/07/11 4:44p Artems
// EIP 53374: Replaced tabs with spaces
//
// 25 12/17/10 12:57p Davidd
// [TAG] EIP47366
// [Category] Improvement
// [Description] Preserve Bios password when CMOS is bad
// [Files] OemDxe.c
// OemPort.c
//
// 24 10/06/10 2:03p Felixp
//
// 22 3/01/10 3:42p Olegi
// Modified Pre/PostProcessOprom functions: added new argument that points
// to the ROM to be executed. This is needed for cases where PciIo is NULL
// (User ROMs). EIP34085.
//
// 21 11/25/09 5:51p Felixp
//
// 19 11/17/09 10:12p Olegi
// Fix in CsmPlatform_PostProcessOpRom related to the previous check-in.
//
// 18 11/17/09 3:11p Olegi
// CSM specific call that would let OEM function recieve control before
// OpROM execution. EIP#20571.
//
// 17 6/25/09 6:09p Robert
// Updated Comments and function headers
//
// 15 12/17/07 3:43p Felixp
// 1. Signal protocol event before and after OpROM execution
// 2. Setup option to enable/disable mass storage OpROM execution added
//
// 14 8/31/07 10:10a Rameshraju
// Legacy Console Redirection enabled only when the option rom is
// dispatched.
//
// 13 4/19/07 10:03a Olegi
// CSMSREDIR_SUPPORT token is replaced with LEGACYSREDIR_SUPPORT
//
// 12 17/04/07 11:05a Anandakrishnanl
// Reverting Back to Version9
//
// 9 3/28/07 10:39a Olegi
// Legacy Serial Redirection Support added
//
// 8 3/28/07 10:22a Yakovlevs
// Code cleanup
//
// 6 10/24/06 12:22p Felixp
// Cosmetic changes
//
// 5 8/30/06 2:59p Fredericko
// -Fix problem with CD-ROM not showing as a boot option in setup
//
// 4 7/25/06 7:07p Ambikas
//
// 3 7/17/06 7:20p Felixp
// #if CSM_SUPPORT added so that module builds without CSM
//
// 1 6/13/06 4:54p Sivagarn
// Initial Checkin
//
//
//*****************************************************************************
//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name: OEMDXE.C
//
// Description:
// This file contains code for Template OEM initialization in the DXE stage
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>
//============================================================================
// Module specific Includes
#include "Efi.h"
#include "token.h"
#include <AmiLib.h>
#include <AmiDxeLib.h>
#include <AmiLoadCsmPolicy.h>
//============================================================================
// Consumed Protocols
#include <Protocol\PciIo.h>
#include <Setup.h>
#include <Protocol\Cpu.h>
#include <Protocol\PciRootBridgeIo.h>
#include <Pci.h>
#if CSM_SUPPORT
#include <Protocol\CsmPlatform.h>
#endif
#if CLEAR_NVRAM_IF_CMOS_BAD
#include <hob.h>
#include <Protocol\SimpleTextIn.h>
#endif // CLEAR_NVRAM_IF_CMOS_BAD
#include <Protocol/ConsoleControl.h>
#include <Protocol/GraphicsOutput.h>
#include <Protocol/DevicePath.h>
//============================================================================
// Constant definitions
#define PCIE_CFG_ADDR(bus,dev,func,reg) \
((VOID*) (PCIEX_BASE_ADDRESS + ((bus) << 20) + ((dev) << 15) + ((func) << 12) + reg))
//============================================================================
// GUID Definitions
//============================================================================
// Variable Declaration
SETUP_DATA *SetupData = NULL;
EFI_GUID SetupGuid = SETUP_GUID;
EFI_GUID OpromStartEndProtocolGuid = OPROM_START_END_PROTOCOL_GUID;
typedef struct {
UINT8 Device;
UINT8 Function;
} PCI_BRG_INFO;
//============================================================================
// Function Prototypes
#if CSM_SUPPORT
#if !defined(CSM_VERSION_BUILD) || (CSM_VERSION_BUILD < 72)
EFI_STATUS
CsmPlatform_PreProcessOpRom (
IN CSM_PLATFORM_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL *PciIo
);
EFI_STATUS
CsmPlatform_PostProcessOpRom (
IN CSM_PLATFORM_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL *PciIo
);
#else
EFI_STATUS
CsmPlatform_PreProcessOpRom (
IN CSM_PLATFORM_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL *PciIo,
IN VOID **RomImage
);
EFI_STATUS
CsmPlatform_PostProcessOpRom (
IN CSM_PLATFORM_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL *PciIo,
IN VOID **RomImage
);
#endif
EFI_STATUS
CsmPlatform_GetAtapiDeviceType (
IN CSM_PLATFORM_PROTOCOL *This,
IN struct _ATAPI_IDENTIFY *IdentifyDriveData,
OUT UINT16 *DevType
);
CSM_PLATFORM_PROTOCOL CsmPlatformProtocol =
{ CsmPlatform_PreProcessOpRom,
CsmPlatform_PostProcessOpRom,
CsmPlatform_GetAtapiDeviceType
};
EFI_STATUS InstallCsmPlatformProtocol();
#endif
//============================================================================
// Function Definitions
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure: SignalProtocolEvent
//
// Description:
// Internal function that installs/uninstall protocol with a specified GUID.
// Such protocols can be used as event signaling mechanism.
//
// Input:
// IN EFI_GUID *ProtocolGuid - Pointer to the protocol GUID
// IN VOID *Interface - Pointer to the interface that allows to pass data
// pointer to the event consumer.
//
// Output:
// None
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID SignalProtocolEvent(IN EFI_GUID *ProtocolGuid, IN VOID *Interface){
EFI_HANDLE Handle = NULL;
pBS->InstallProtocolInterface (
&Handle, ProtocolGuid, EFI_NATIVE_INTERFACE, Interface
);
pBS->UninstallProtocolInterface (
Handle, ProtocolGuid, Interface
);
}
#if CLEAR_NVRAM_IF_CMOS_BAD
#define AMITSESETUP_GUID \
{ 0xc811fa38, 0x42c8, 0x4579, 0xa9, 0xbb, 0x60, 0xe9, 0x4e, 0xdd, 0xfb, 0x34 }
#define PASSWORD_HOB_GUID \
{ 0x79ce097a, 0x91aa, 0x41ff, 0xb3, 0xa8, 0x53, 0x45, 0x59, 0xb3, 0x0d, 0xb1 }
typedef struct {
EFI_HOB_GUID_TYPE EfiHobGuidType;
AMITSESETUP AmiTseData;
}
PASSWORD_HOB;
//<AMI_PHDR_START>
//----------------------------------------------------------------------
// Procedure: RestoreSetupPassword
//
// Description: Restore previous Password
//
// Input: IN EFI_EVENT Event
// IN VOID *Context
//
// Output: NONE
//
// Returns: NONE
//
//----------------------------------------------------------------------
//<AMI_PHDR_END>
VOID
RestoreSetupPassword (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
EFI_GUID HobListGuid = HOB_LIST_GUID;
EFI_GUID PwdHobGuid = PASSWORD_HOB_GUID;
EFI_GUID AmiTseSetupGuid = AMITSESETUP_GUID;
VOID *pHobList;
UINTN VariableSize = sizeof(AMITSESETUP);
pHobList = GetEfiConfigurationTable(pST, &HobListGuid);
if (pHobList != NULL) {
Status = FindNextHobByGuid(&PwdHobGuid, &pHobList);
}
if (Status == EFI_SUCCESS) {
pRS->SetVariable(
L"AMITSESetup",
&AmiTseSetupGuid,
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
VariableSize,
&((PASSWORD_HOB*)pHobList)->AmiTseData);
}
pBS->CloseEvent(Event);
}
#endif // CLEAR_NVRAM_IF_CMOS_BAD
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure: OEMDXE_Init
//
// Description:
// This function is the entry point for this DXE. This function programs
// OEM defined values in the DXE stage
//
// Input:
// IN EFI_HANDLE ImageHandle - Image handle
// IN EFI_SYSTEM_TABLE *SystemTable - Pointer to the system table
//
// Output:
// EFI_SUCCESS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
OEMDXE_Init (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable )
{
UINTN SetupSize = 0;
#if CLEAR_NVRAM_IF_CMOS_BAD
EFI_EVENT HobPwdEvent;
VOID *Registration;
EFI_GUID gSimpleInGuid = EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID;
#endif // CLEAR_NVRAM_IF_CMOS_BAD
InitAmiLib(ImageHandle,SystemTable);
GetEfiVariable(L"Setup", &SetupGuid, NULL, &SetupSize, &SetupData);
#if CLEAR_NVRAM_IF_CMOS_BAD
HobPwdEvent = NULL;
//
// Create event for SimpleInProtocol Callback notification
//
pBS->CreateEvent (
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
RestoreSetupPassword,
NULL,
&HobPwdEvent
);
pBS->RegisterProtocolNotify (&gSimpleInGuid, HobPwdEvent, &Registration);
#endif // CLEAR_NVRAM_IF_CMOS_BAD
#if CSM_SUPPORT
InstallCsmPlatformProtocol();
#endif
return EFI_SUCCESS;
}
#if CSM_SUPPORT
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure: CsmPlatform_PreProcessOpRom
//
// Description:
// This function is the member function PreProcessOpRom of the CsmPlatformProtocol.
//
// Input:
// CSM_PLATFORM_PROTOCOL *This - Pointer to this instance of the CSM_PLATFORM_PROTOCOL
// EFI_PCI_IO_PROTOCOL *PciIo - OPTIONAL - pointer to the instance of the PciIo Protocol
//
// Output:
// EFI_SUCCESS - run the option rom for this device
// EFI_ABORTED - code determined to not run Oprom for this device
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
#if defined(CSM_VERSION_BUILD) && (CSM_VERSION_BUILD > 71)
EFI_STATUS
CsmPlatform_PreProcessOpRom (
IN CSM_PLATFORM_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL *PciIo,
IN VOID **RomImage
)
#else
EFI_STATUS
CsmPlatform_PreProcessOpRom (
IN CSM_PLATFORM_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL *PciIo
)
#endif
{
CSM_PLATFORM_POLICY_DATA CsmOpromPolicyData;
#if defined(CSM_VERSION_BUILD) && (CSM_VERSION_BUILD > 71)
VOID* RomLocation = *RomImage;
if (RomImage != NULL){
if (((LEGACY_OPT_ROM_HEADER*)RomLocation)->Signature == 0xAA55) {
//
// TODO: Add platform pre-OpROM function here for that ROM image
// is no hardware associated.
}
}
#endif
// See if any callback function wishes to cancel this OpROM execution
CsmOpromPolicyData.PciIo = PciIo;
CsmOpromPolicyData.ExecuteThisRom = TRUE;
SignalProtocolEvent(&OpromStartEndProtocolGuid, &CsmOpromPolicyData);
return ( CsmOpromPolicyData.ExecuteThisRom == FALSE) ? EFI_ABORTED : EFI_SUCCESS;
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure: CsmPlatform_PostProcessOpRom
//
// Description:
// This function is member function PostProcessOpRom of the CsmPlatformProtocol.
//
// Input:
// CSM_PLATFORM_PROTOCOL *This - Pointer to this instance of the CSM_PLATFORM_PROTOCOL
// EFI_PCI_IO_PROTOCOL *PciIo - OPTIONAL - pointer to the instance of the PciIo Protocol
//
// Output:
// EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
#if defined(CSM_VERSION_BUILD) && (CSM_VERSION_BUILD > 71)
EFI_STATUS
CsmPlatform_PostProcessOpRom (
IN CSM_PLATFORM_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL *PciIo,
IN VOID **RomImage
)
#else
EFI_STATUS
CsmPlatform_PostProcessOpRom (
IN CSM_PLATFORM_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL *PciIo
)
#endif
{
// signal the OpromStartEndProtocolGuid event
SignalProtocolEvent(&OpromStartEndProtocolGuid, NULL);
return EFI_SUCCESS;
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure: InstallCsmPlatformProtocol
//
// Description:
// This function is the entry point for the OEM DXE portion of the Board
// template driver
//
// Input:
// None
//
// Output:
// EFI_STATUS value determined by the call to InstallProtocolInterface
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS InstallCsmPlatformProtocol()
{
EFI_HANDLE Handle = 0;
return pBS->InstallProtocolInterface (
&Handle, &gCsmPlatformProtocolGuid,
EFI_NATIVE_INTERFACE, &CsmPlatformProtocol
);
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure: CsmPlatform_GetAtapiDeviceType
//
// Description:
// This function is the member function GetAtapiDeviceType of the
// CsmPlatformProtocol. Until ported, this function returns EFI_UNSUPPORTED
//
// Input:
// IN CSM_PLATFORM_PROTOCOL *This - pointer to the instance of the CSM Platform Protocol
// IN struct _ATAPI_IDENTIFY *IdentifyDriveData - pointer to Atapi Drive Data structure
// OUT UINT16 *DevType - type of the device the IdentifyDeviceData is for
//
// Output:
// EFI_UNSUPPORTED
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
CsmPlatform_GetAtapiDeviceType (
IN CSM_PLATFORM_PROTOCOL *This,
IN struct _ATAPI_IDENTIFY *IdentifyDriveData,
OUT UINT16 *DevType
)
{
return EFI_UNSUPPORTED;
}
#endif
//**********************************************************************
//**********************************************************************
//** **
//** (C)Copyright 1985-2009, American Megatrends, Inc. **
//** **
//** All Rights Reserved. **
//** **
//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
//** **
//** Phone: (770)-246-8600 **
//** **
//**********************************************************************
//**********************************************************************
|