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
|
//*************************************************************************
//*************************************************************************
//** **
//** (C)Copyright 1985-2011, American Megatrends, Inc. **
//** **
//** All Rights Reserved. **
//** **
//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
//** **
//** Phone: (770)-246-8600 **
//** **
//*************************************************************************
//*************************************************************************
//
//*************************************************************************
// $Header: /Alaska/BIN/IO/Fintek/F81866/F81866Setup.C 2 12/14/11 9:45p Kasalinyi $
//
// $Revision: 2 $
//
// $Date: 12/14/11 9:45p $
//*************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/IO/Fintek/F81866/F81866Setup.C $
//
// 2 12/14/11 9:45p Kasalinyi
// [TAG] EIPNone
// [Category] Improvement
// [Description] Fix setup screen display "??" char
// [Files] F81865Setup.C
//
// 1 7/20/11 4:22a Kasalinyi
// [Category] Improvement
// [Description] Initial Porting
// [Files] F81866.CIF
// IO_F81866.SDL
// F81866.ASL
// F81866.MAK
// F81866.SD
// F81866.UNI
// F81866DXE.C
// F81866PEI.C
// F81866PeiDebugger.C
// F81866Setup.C
// F81866Setup.H
// History.txt
// F81866.chm
//
// 4 3/21/11 9:41p Mikes
// seperate the core and oem job
//
//*************************************************************************
//<AMI_FHDR_START>
//
// Name: <F81866Setup.C>
//
// Description: Setup related Routines.
//
//<AMI_FHDR_END>
//*************************************************************************
//-------------------------------------------------------------------------
// Include Files
//-------------------------------------------------------------------------
#include <Efi.h>
#include <AmiDxeLib.h>
#include <GenericSio.h>
#include "F81866Setup.H"
#include "SetupStringList.h"
//-------------------------------------------------------------------------
// Constants, Macros and Type Definitions
//-------------------------------------------------------------------------
typedef void (HWM_EXTERNAL_FUN)(
IN OUT HWM_DATA * Data
);
typedef struct{
UINT8 Type;
UINT8 UID;
UINT16 StrTokenV;
}STR_UID;
//-------------------------------------------------------------------------
//Variable, Prototype, and External Declarations
//-------------------------------------------------------------------------
static VOID SetSioStrings(
IN SPIO_DEV *Dev,
IN EFI_HII_HANDLE HiiHandle
);
STR_UID SetupStringsList[] = { STR_TABLE_LIST {0xff,0xff,0xffff}};
//----------------------------------
extern HWM_EXTERNAL_FUN HWM_External_Fun_LIST EndOfFunList;
static HWM_EXTERNAL_FUN* OemHwmExternalFunList[] = {HWM_External_Fun_LIST NULL};
void AdjustString(
IN OUT CHAR16 * Buffer,
IN CHAR16 * StringToChged,
IN UINT8 STCLen,
IN CHAR16 * HeadBuf,
IN UINT8 HeadLen,
IN BOOLEAN Flag,
IN UINT8 MidPos,
IN CHAR16 * TailBuf,
IN UINT8 TailLen
);
UINTN
HHMEfiValueToString (
IN OUT CHAR16 *Buffer,
IN INT64 Value,
IN UINTN Flags,
IN UINTN Width
);
void HHMCommon(
IN UINTN RegData,
IN UINT8 Func,
IN UINT16 StrToken,
IN UINT8 RefValue,
EFI_HII_HANDLE hiiHandle
);
/////////////////////////////////////////////////////////////////////////////
//Below function will update HII database's SIO strings, before enter setup
/////////////////////////////////////////////////////////////////////////////
//<AMI_PHDR_START>
//---------------------------------------------------------------------------
// Procedure: InitSioSetupStrings
//
// Description:
// This function provide SIO Setup screen display string.
//
// Input:
// IN IN UINT16 Class
// IN EFI_HII_HANDLE *HiiHandle
//
// Output: VOID
//
// Modified: Nothing
//
// Referrals: None
//
// Note:
//-------------------------------------------------------------------------
// <AMI_PHDR_END>
VOID InitSioSetupStrings(
IN EFI_HII_HANDLE HiiHandle,
IN UINT16 Class)
{
static EFI_GUID siopg=EFI_AMI_SIO_PROTOCOL_GUID;
SPIO_DEV *dev;
UINTN i,hcnt;
EFI_HANDLE *hbuff;
EFI_STATUS Status=0;
if(Class == ADVANCED_FORM_SET_CLASS) {
Status=pBS->LocateHandleBuffer(ByProtocol,&siopg, NULL, &hcnt,&hbuff);
if (EFI_ERROR(Status)) hcnt = 0;
for (i=0; i<hcnt; i++) {
Status = pBS->HandleProtocol ( hbuff[i],&siopg,(VOID*)&dev);
ASSERT_EFI_ERROR(Status);
if(dev->DeviceInfo->HasSetup) SetSioStrings(dev, HiiHandle);
}
}
}
// <AMI_PHDR_START>
//-------------------------------------------------------------------------
//
// Procedure: SetSioStrings
//
// Description:
// This function provide SIO's each logic device Setup screen display string.
//
// Input:
// IN SPIO_DEV *Dev - SPIO Device Private Data section
// IN EFI_HII_HANDLE *HiiHandle
//
// Output: None
//
// Modified: Nothing
//
// Referrals: None
//
// Note:
//-------------------------------------------------------------------------
// <AMI_PHDR_END>
static VOID SetSioStrings(
IN SPIO_DEV *Dev,
IN EFI_HII_HANDLE HiiHandle)
{
UINT8 i;
CHAR8 pString8[80];
CHAR16 pString16[80];
if((!Dev->NvData.DevEnable) || (!Dev->VlData.DevImplemented)) return;
if(Dev->VlData.DevDma1) {
if(Dev->VlData.DevIrq1)
Sprintf(pString8, "IO=%Xh; IRQ=%d; DMA=%d;", Dev->VlData.DevBase1,Dev->VlData.DevIrq1,Dev->VlData.DevDma1);
else
Sprintf(pString8, "IO=%Xh; DMA=%d;",Dev->VlData.DevBase1, Dev->VlData.DevDma1);
}
else {
if(Dev->VlData.DevIrq1)
Sprintf(pString8, "IO=%Xh; IRQ=%d;",Dev->VlData.DevBase1,Dev->VlData.DevIrq1);
else
Sprintf(pString8, "IO=%Xh;",Dev->VlData.DevBase1);
}
for(i=0;(i < 0x80) && (pString8[i] != 0);i++)
pString16[i] = (CHAR16)pString8[i];
pString16[i++] = 0;
for(i=0;;i++) {
if(SetupStringsList[i].Type == 0xFF) break;
if((SetupStringsList[i].UID == Dev->DeviceInfo->UID) && \
(SetupStringsList[i].Type == Dev->DeviceInfo->Type)) {
InitString(HiiHandle,SetupStringsList[i].StrTokenV,pString16);
return;
}
}
return;
}
/////////////////////////////////////////////////////////////////////////////
//Below function will update hardware monitor value dynamically
//No porting needed
/////////////////////////////////////////////////////////////////////////////
//<AMI_PHDR_START>
//-------------------------------------------------------------------------
// Procedure: F81866_HWM_CallBack
//
// Description:
// Form Callback Function.Will be called every 100m Polling for data Updates.
//
// Input:
// IN EFI_HII_HANDLE HiiHandle
// IN UINT16 Class
// IN UINT16 SubClass
// IN UINT16 Key
//
// Output: VOID
//
// Modified: Nothing
//
// Referrals: None
//
// Note:
//-------------------------------------------------------------------------
//<AMI_PHDR_END>
void F81866_HWM_CallBack(
IN EFI_HII_HANDLE HiiHandle,
IN UINT16 Class,
IN UINT16 SubClass,
IN UINT16 Key
)
{
//EFI_STATUS Status;
HWM_DATA Data;
UINT8 i;
//-------------------------------------------------------------------------
//AMI_TO: AMI need to porting the register where they goto read.
//-------------------------------------------------------------------------
for(i=0; OemHwmExternalFunList[i]; i++)
{
OemHwmExternalFunList[i](&Data);
HHMCommon(Data.Value, Data.Type, Data.Token, Data.OddPos, HiiHandle);
}
return ;
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------
// Procedure: HHMEfiValueToString
//
// Description:
// This function Adjust the String shows in setup screen
//
// Input:
// INT64 Value ->Value need change to string
// UINTN Flags ->Comma type
// UINTN Width ->Character number for value
// CHAR16 *Buffer ->Temp string for this change
// Output:
//
// OPTIONAL:
// None
//
// Returns:
// Index
//
//----------------------------------------------------------------------
//<AMI_PHDR_END>
UINTN
HHMEfiValueToString (
IN OUT CHAR16 *Buffer,
IN INT64 Value,
IN UINTN Flags,
IN UINTN Width
) {
CHAR16 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];
CHAR16 *TempStr;
CHAR16 *BufferPtr;
UINTN Count;
UINTN ValueCharNum;
UINTN Remainder;
CHAR16 Prefix;
UINTN Index;
BOOLEAN ValueIsNegative;
TempStr = TempBuffer;
BufferPtr = Buffer;
Count = 0;
ValueCharNum = 0;
ValueIsNegative = FALSE;
if (Width > CHARACTER_NUMBER_FOR_VALUE - 1) {
Width = CHARACTER_NUMBER_FOR_VALUE - 1;
}
if (Value < 0) {
*(TempStr++) = '-';
Value = -Value;
ValueCharNum++;
Count++;
ValueIsNegative = TRUE;
}
do {
if ((Width != 0) && (Count >= Width)) break;
Value = (UINT64)Div64 ((UINT64)Value, 10, &Remainder);
*(TempStr++) = (CHAR16)(Remainder + '0');
ValueCharNum++;
Count++;
if ((Flags & COMMA_TYPE) == COMMA_TYPE) {
if (Value != 0) {
if ((ValueIsNegative && (ValueCharNum % 3 == 1)) || \
((!ValueIsNegative) && (ValueCharNum % 3 == 0))) {
*(TempStr++) = ',';
Count++;
}
}
}
} while (Value != 0);
if (Flags & PREFIX_ZERO) Prefix = '0';
else Prefix = ' ';
Index = Count;
if (!(Flags & LEFT_JUSTIFY)) {
for (; Index < Width; Index++)
*(TempStr++) = Prefix;
}
//
// Reverse temp string into Buffer.
//
if (Width == 0) {
while (TempStr != TempBuffer)
*(BufferPtr++) = *(--TempStr);
}
else {
Index = 0;
while ((TempStr != TempBuffer) && (Index++ < Width))
*(BufferPtr++) = *(--TempStr);
}
*BufferPtr = 0;
return Index;
}
//<AMI_PHDR_START>
//-------------------------------------------------------------------------
// Procedure: AdjustString
//
// Description:
// Adjust string with float point
//
// Input:
// Buffer -> defautl string. ": N/A ". Buffer length should more than 0x10
// StringToChged -> Raw data
// STCLen -> String total length
// HeadBuf -> Header of string
// HeadLen -> Header length
// Flag -> TRUE indicate is a float data, False indicate it's a integet data.
// MidPos -> Float point position. eg: 0.076 is 0x3
// TailBuf -> unit of string data
// TailLen -> Length of unit
//
// Output: Return string in Buffer
//
//-------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID AdjustString(
IN OUT CHAR16 * Buffer,
IN CHAR16 * StringToChged,
IN UINT8 STCLen,
IN CHAR16 * HeadBuf,
IN UINT8 HeadLen,
IN BOOLEAN Flag,
IN UINT8 MidPos,
IN CHAR16 * TailBuf,
IN UINT8 TailLen
) {
CHAR16 *temp = Buffer;
CHAR16 *TempSrc = StringToChged;
CHAR16 dod[] ={L"."};
CHAR16 Zero[] ={L"0"};
pBS->SetMem(temp, STR_BUFFER_LENGTH * sizeof(CHAR16), 0);
if(HeadLen) {
//Add the leading string
pBS->CopyMem(temp, HeadBuf, (HeadLen * sizeof(CHAR16)));
temp += HeadLen;
}
if (!Flag) {
//Add the float point->L"."
pBS->CopyMem(temp, TempSrc, (STCLen * sizeof(CHAR16))); //Add the string before float point
temp += STCLen; TempSrc += STCLen;
goto not_float_data;
}
if(STCLen <= MidPos) {
//make up with a zero
pBS->CopyMem(temp, Zero, (0x01 * sizeof(CHAR16))); //Copy a 0
temp++;
} else {
pBS->CopyMem(temp, TempSrc, ((STCLen - MidPos) * sizeof(CHAR16))); //Add the string before float point
temp += (STCLen - MidPos); TempSrc += (STCLen - MidPos);
}
pBS->CopyMem(temp, dod, 0x01 * sizeof(CHAR16)); //Add the float point->L"."
temp++;
if(STCLen < MidPos) {
//make up with a zero
pBS->CopyMem(temp, Zero, ((MidPos - STCLen) * sizeof(CHAR16)));//Copy a 0
pBS->CopyMem(temp, TempSrc, ((STCLen) * sizeof(CHAR16))); //Add the string after float point
temp += MidPos; TempSrc += MidPos;
} else {
pBS->CopyMem(temp, TempSrc, ((MidPos) * sizeof(CHAR16))); //Add the string after float point
temp += MidPos; TempSrc += MidPos;
}
not_float_data:
if (TailLen) {
//Add the unit
pBS->CopyMem(temp, TailBuf, (TailLen * sizeof(CHAR16)));
}
return;
}
//<AMI_PHDR_START>
//-------------------------------------------------------------------------
// Procedure: HHMCommon
//
// Description:
// Update option with the data read from register
//
// Input:
// RegData -> data from SIO registers
// Func -> Fan Speed,Voltage and Temperature
// StrToken -> String token
// OddPos -> Odd position
// hiiHandle
// gblHii
//
// Output:
// Return string in Buffer
//
//-------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID HHMCommon(
IN UINTN RegData,
IN UINT8 Func,
IN UINT16 StrToken,
IN UINT8 OddPos,
IN EFI_HII_HANDLE hiiHandle
) {
CHAR16 TailRound[] = L" RPM"; //Fan uint
CHAR16 TailVoltg[] = L" V"; //Voltage uint
CHAR16 TailTempt[] = L" C"; //Temperature uint
CHAR16 LeadingMini[] = L": -"; //Fix
CHAR16 LeadingPlus[] = L": +"; //Fix
CHAR16 LeadingSpac[] = L": "; //Fix
CHAR16 AllSpace[] = L": N/A "; //Fix
CHAR16 *TempStr = AllSpace;
UINT8 StrLen;
UINT64 NData;
CHAR16 StrUp[STR_BUFFER_LENGTH] = L": N/A "; //Don't change this line
CHAR16 *StrUpdated = StrUp;
TailTempt[1]=0x2103;
NData = (UINT64)(RegData);
//The following may be ported by each SIO
//As now, it support max length is five
if(NData>9999) StrLen = 0x5;
else if(NData>999) StrLen = 0x4;
else if(NData>99) StrLen = 0x3;
else if(NData>9) StrLen = 0x2;
else StrLen = 0x1;
//When device not present, update to 'N/A'
if(NData == 0x00) StrUpdated = StrUp;
else {
HHMEfiValueToString(TempStr, NData, 0, StrLen);
switch(Func) {
case VOLTAGE: //Indicate it's voltage
AdjustString(StrUpdated, TempStr, StrLen, LeadingPlus, 0x03,\
OddPos?TRUE:FALSE, OddPos, TailVoltg, 0x02);
break;
case TEMPERATURE: //Indicate it's Temperature
AdjustString(StrUpdated, TempStr, StrLen, LeadingPlus, 0x03,\
OddPos?TRUE:FALSE, OddPos, TailTempt, 0x02);
break;
case FAN_SPEED: //Indicate it's fan
AdjustString(StrUpdated, TempStr, StrLen, LeadingSpac, 0x02,\
OddPos?TRUE:FALSE, OddPos, TailRound, 0x04);
break;
default : //Default to " N/A "
break;
}
}
InitString(hiiHandle, StrToken, StrUpdated);
return;
}
//*************************************************************************
//*************************************************************************
//** **
//** (C)Copyright 1985-2011, American Megatrends, Inc. **
//** **
//** All Rights Reserved. **
//** **
//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
//** **
//** Phone: (770)-246-8600 **
//** **
//*************************************************************************
//*************************************************************************
|