summaryrefslogtreecommitdiff
path: root/Core/EM/Terminal/InitTerminalStrings.c
blob: b7512e80bdde40176a8a6c33121df5e38993d51c (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
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
//****************************************************************************
//****************************************************************************
//**                                                                        **
//**             (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/Modules/Terminal/InitTerminalStrings.c 22    12/12/11 6:51a Rajeshms $
//
// $Revision: 22 $
//
// $Date: 12/12/11 6:51a $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/Modules/Terminal/InitTerminalStrings.c $
// 
// 22    12/12/11 6:51a Rajeshms
// [TAG]  		EIP71636 
// [Category]  	New Feature
// [Description]  	Implement the AMI_SERIAL_PROTOCOL for non-generic PCI
// Serial Device.
// [Files]  		AmiSerial.c, AmiSerial.sdl, AmiSerial.mak, AmiSerial.chm,
// AmiSerial.dxs, AmiSerial.cif, Terminal.c, SerialIo.c, TerminalSetup.c,
// InitTerminalStrings.c, TerminalSetupVar.h, Terminal.cif,
// TerminalAmiSerial.h, LegacySredir_Setup.c
// 
// 21    3/02/11 3:15a Rameshr
// [TAG]- EIP 54313
// [Category]-IMPROVEMENT
// [Description]- Terminal driver Getvariable calls assumed to have valid
// values. Added code to return the error code when there is an failure in
// the getvariable call. 
// [Files]- TerminalSetup.c, InitTerminalString.c
// 
// 20    11/02/10 4:17a Lavanyap
// [TAG] - EIP42299
// [Category] - IMPROVEMENT
// [Description] - Console Redirection can support 10 COM Ports.
// [Files] - InitTerminalStrings.c, SerialIo.c, Terminal.sd, 
//           Terminal.sdl, Terminal.uni, TerminalSetup.c
// 
// 19    10/19/10 8:35a Rajeshms
// [TAG]- EIP 39562
// [Category]-IMPROVEMENT
// [Description]- Show entire PCI address of redirection device in Setup
// [Files]- Terminal.c, TerminalSetup.c, InitTerminalStrings.c
// 
// 18    1/20/10 4:47p Artems
// EIP 34000 - made UEFI 2.1 changes backward compatible
// 
// 17    12/16/09 4:33p Artems
// EIP 31619 added UEFI 2.1 support
// 
// 16    11/18/09 10:28a Fasihm
// EIP#30023 - Fix added to resolve the NVRAM Corruption issue in the
// projects.
// 
// 15    7/02/09 5:01p Rameshr
// Coding Standard and File header updated.
// 
// 14    4/14/08 4:55p Ambikas
// 
// 13    4/14/08 2:33p Ambikas
// 
// 12    6/18/07 6:38p Ambikas
// 
// 11    6/12/07 3:53p Ambikas
// 
// 10    6/11/07 11:35a Ambikas
// 
// 9     6/10/07 6:02p Ambikas
// 
// 8     6/06/07 7:55p Ambikas
// We no longer print segment and bus numbers of pci serial device, just
// device and function numbers.
// 
// 7     6/05/07 6:26p Ambikas
// 
// 6     6/05/07 6:16p Ambikas
// 
// 5     6/05/07 11:44a Ambikas
// 
// 4     6/05/07 11:43a Ambikas
// 
// 3     6/05/07 11:40a Ambikas
// 
// 2     6/04/07 7:32p Ambikas
// -Increased the max number of pci serial ports to 4.  Added extra strings
//  for the additional ports.
// -If TOTAL_SERIAL_PORTS is 0, then the setup data structures for the 
//  serial ports in Terminal.sd will not be defined.  So, we comment out
//  code which references those data structures and just return default 
//  values.  
//
// 1     5/24/2007 2:33p Ambikas
//
//**********************************************************************
//<AMI_FHDR_START>
//
// Name: InitTerminalStrings.c
//
// Description: Contains InitTerminalStrings(), which is linked to 
//              SetupStringInit in the sdl page.  Before entering setup,
//              we do any modification or updating needed for the serial
//              port name strings (STR_SIO_SERIAL_PORT0, etc.).
//
//<AMI_FHDR_END>
//**********************************************************************

#include <AmiLib.h>
#include <AmiDxeLib.h>
#include <Setup.h>
#include <SetupStrTokens.h>
#include <Token.h>
#include "TerminalSetupVar.h"

#ifndef HII_LIBRARY_FUNCTIONS_SUPPORT
EFI_STATUS HiiLibGetString(
	IN EFI_HII_HANDLE HiiHandle, 
    IN STRING_REF StringId, 
	IN OUT UINTN *StringSize, 
    OUT EFI_STRING String
);
EFI_STATUS HiiLibSetString(
	IN EFI_HII_HANDLE HiiHandle, 
    IN STRING_REF StringId, 
    IN EFI_STRING String
);
#endif


STRING_REF gSioSerialPortStrRef[MAX_SIO_SERIAL_PORTS] = {
    STRING_TOKEN(STR_SIO_SERIAL_PORT0), 
    STRING_TOKEN(STR_SIO_SERIAL_PORT1), 
    STRING_TOKEN(STR_SIO_SERIAL_PORT2), 
    STRING_TOKEN(STR_SIO_SERIAL_PORT3),
    STRING_TOKEN(STR_SIO_SERIAL_PORT4), 
    STRING_TOKEN(STR_SIO_SERIAL_PORT5), 
    STRING_TOKEN(STR_SIO_SERIAL_PORT6), 
    STRING_TOKEN(STR_SIO_SERIAL_PORT7), 
    STRING_TOKEN(STR_SIO_SERIAL_PORT8), 
    STRING_TOKEN(STR_SIO_SERIAL_PORT9)
};

STRING_REF gPciSerialPortStrRef[MAX_PCI_SERIAL_PORTS] = {
    STRING_TOKEN(STR_PCI_SERIAL_PORT0), 
    STRING_TOKEN(STR_PCI_SERIAL_PORT1), 
    STRING_TOKEN(STR_PCI_SERIAL_PORT2), 
    STRING_TOKEN(STR_PCI_SERIAL_PORT3) 
};

UINT32 gTotalSioSerialPorts = TOTAL_SIO_SERIAL_PORTS;
UINT32 gTotalPciSerialPorts = TOTAL_PCI_SERIAL_PORTS;

EFI_GUID gTerminalVarGuid = TERMINAL_VAR_GUID;

//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure: StrCat
//
// Description: Wrapper function around Wcscpy.  
//              Concantenates the second Unicode string to the first.
//
// Input: 
//      IN OUT CHAR16 *Destination
//      IN CHAR16 *Source
//
// Output: VOID
//
//<AMI_PHDR_END>
//**********************************************************************  
VOID StrCat (IN OUT CHAR16 *Destination, IN CHAR16 *Source)
{
    Wcscpy (Destination + Wcslen (Destination), Source);
}

//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure: InitTerminalStrings
//
// Input: 
//      IN EFI_HII_HANDLE HiiHandle
//      IN UINT16 Class
//
// Output: VOID
//
// Description: Certain strings in the terminal setup page can only be 
//              updated at runtime, which is what this function does.  
//              The pci serial port names are changed to contain the 
//              location (device and function numbers) of the port.  
//              If any serial ports are disabled, "Disabled" 
//              is concatenated to their names.  
//
// Output:
//
//<AMI_PHDR_END>
//**********************************************************************  
VOID InitTerminalStrings(IN EFI_HII_HANDLE HiiHandle, IN UINT16 Class)
{
#if (TOTAL_SERIAL_PORTS > 0)

    EFI_STATUS Status = EFI_SUCCESS;

    UINTN SerialPortsEnabledVarSize = sizeof(SERIAL_PORTS_ENABLED_VAR);
    SERIAL_PORTS_ENABLED_VAR SerialPortsEnabledVar; 
    UINT32 SerialPortsEnabledVarAttributes=0;

#if (TOTAL_PCI_SERIAL_PORTS > 0)
    UINTN PciSerialPortsLocationVarSize 
                                = sizeof(PCI_SERIAL_PORTS_LOCATION_VAR);
    PCI_SERIAL_PORTS_LOCATION_VAR PciSerialPortsLocationVar; 
    UINT32 PciSerialPortsLocationVarAttributes=0;
#endif

    UINT32 i = 0; 

    CHAR16 Str[512]=L"";
    CHAR16 Str2[512]=L"";
    UINTN Size=512;

    if (Class==ADVANCED_FORM_SET_CLASS) {
        Status = pRS->GetVariable(SERIAL_PORTS_ENABLED_VAR_C_NAME, 
                                    &gTerminalVarGuid,
                                    &SerialPortsEnabledVarAttributes, 
                                    &SerialPortsEnabledVarSize,
                                    &SerialPortsEnabledVar);
	
	if (EFI_ERROR(Status)) {
		return;
	}

#if (TOTAL_PCI_SERIAL_PORTS > 0)
        Status = pRS->GetVariable(PCI_SERIAL_PORTS_LOCATION_VAR_C_NAME, 
                                    &gTerminalVarGuid, 
                                    &PciSerialPortsLocationVarAttributes, 
                                    &PciSerialPortsLocationVarSize,
                                    &PciSerialPortsLocationVar);
        ASSERT_EFI_ERROR(Status);

        if (EFI_ERROR(Status)) {
            return;
        }
#endif

        for (i = 0; i < gTotalSioSerialPorts; i++) {
            if (!SerialPortsEnabledVar.PortsEnabled[i]) {
                Size = 512;
                Status = HiiLibGetString(HiiHandle, 
                                            gSioSerialPortStrRef[i],
                                            &Size, Str);
                if (!EFI_ERROR(Status)) {
                    StrCat(Str, L" (Disabled)");
                    InitString(HiiHandle,  gSioSerialPortStrRef[i], Str);
                }
            }
        }

#if (TOTAL_PCI_SERIAL_PORTS > 0)
        for (i = 0; i < gTotalPciSerialPorts; i++) {
            Size = 512;
            Status = HiiLibGetString(HiiHandle, 
                                        gPciSerialPortStrRef[i],
                                        &Size, Str);
            if (!EFI_ERROR(Status)) {
                if(PciSerialPortsLocationVar.AmiPciSerialPresent[i] == TRUE) {
                    //
                    // If AMI Serial Protcocol was installed for this PCI Serial device,
                    // then display the device like COM3(Pci Bus2,Dev10,Func1,Port0)
                    // with Port information.
                    //
                    Swprintf(Str2, L"COM%X(Pci Bus%d,Dev%d,Func%d,Port%d)",
                                        gTotalSioSerialPorts+i,
                                        PciSerialPortsLocationVar.Bus[i],
                                        PciSerialPortsLocationVar.Device[i],
                                        PciSerialPortsLocationVar.Function[i],
                                        PciSerialPortsLocationVar.Port[i]);
                } else {
                    Swprintf(Str2, L"COM%X(Pci Bus%d,Dev%d,Func%d)",
                                        gTotalSioSerialPorts+i,
                                        PciSerialPortsLocationVar.Bus[i],
                                        PciSerialPortsLocationVar.Device[i],
                                        PciSerialPortsLocationVar.Function[i]);
                }                
    
                StrCat(Str, Str2); 
                if (!SerialPortsEnabledVar.PortsEnabled[gTotalSioSerialPorts+i]) {
                    StrCat(Str, L" (Disabled)");
                }
                InitString(HiiHandle, gPciSerialPortStrRef[i], Str);
            }
        }
#endif
    }
#endif
}

#ifndef HII_LIBRARY_FUNCTIONS_SUPPORT
#include <Protocol/Hii.h>

static EFI_HII_PROTOCOL *Hii = NULL;

static EFI_STATUS HiiLibGetString(
	IN EFI_HII_HANDLE HiiHandle, 
    IN STRING_REF StringId, 
	IN OUT UINTN *StringSize, 
    OUT EFI_STRING String
)
{
    if (Hii == NULL && EFI_ERROR(pBS->LocateProtocol(&gEfiHiiProtocolGuid, NULL, &Hii))) 
        return EFI_NOT_FOUND;

    return Hii->GetString(Hii, HiiHandle, StringId, TRUE, NULL, StringSize, String);
}

static EFI_STATUS HiiLibSetString(
	IN EFI_HII_HANDLE HiiHandle, 
    IN STRING_REF StringId, 
    IN EFI_STRING String
)
{
    if (Hii == NULL && EFI_ERROR(pBS->LocateProtocol(&gEfiHiiProtocolGuid, NULL, &Hii))) 
        return EFI_NOT_FOUND;

    return Hii->NewString(Hii, L"   ", HiiHandle, &StringId, String);
}
#endif

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