summaryrefslogtreecommitdiff
path: root/Board/EM/Thunderbolt/TbtOemBoard/TbtOemBoard.c
blob: ce78068c276414d45848603756702ffe2d6e6172 (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
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
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************
//*************************************************************************
// $Header: /Alaska/SOURCE/Modules/Thunderbolt/TbtOemBoard/TbtOemBoard.c 7     5/19/14 7:38a Barretlin $
//
// $Revision: 7 $
//
// $Date: 5/19/14 7:38a $
//*************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/Thunderbolt/TbtOemBoard/TbtOemBoard.c $
// 
// 7     5/19/14 7:38a Barretlin
// [TAG]  		EIP165410
// [Category]  	New Feature
// [Description]  	Support Thunderbolt AIC at NB PCIE slot
// [Files]  		TbtPei.c TbtDxe.c TbtGpe.asl TbtSmm.c TbtOemBoard.c
// TbtOemLib.c TbtOemLib.h TbtSetup.sdl TbtSetup.sd TbtSetup.uni
// TbtSetupReset.c
// 
// 6     5/19/14 7:15a Barretlin
// [TAG]  		EIP N/A
// [Category]  	Improvement
// [Description]  	Using setup item choose return value of _RMV method in
// ASL code
// [Files]  		TbtDxe.c TbtGpe.asl TbtOemBoard.c TbtOemBoard.h TbtSetup.sd
// TbtSetup.sdl TbtSetup.uni
// 
// 5     2/18/14 2:12a Barretlin
// [TAG]  		EIP N/A
// [Category]  	Improvement
// [Description]  	Release PCIE root port control when Thunderbolt
// function disable in run time
// [Files]  		TbtOemBoard.c
// 
// 4     2/10/14 1:26p Barretlin
// [TAG]  		EIP N/A
// [Category]  	Improvement
// [Description]  	remove useless policy item and setup item
// [Files]  		TbtOemBoard.h TbtOemBoard.c TbSetup.sdl TbtSetup.sd
// TbtSetup.uni TbtSmm.c
// 
// 3     1/05/14 2:06p Barretlin
// [TAG]  		EIP N/A
// [Category]  	New Feature
// [Description]  	Support Thunderbolt feature Enable/Disable in run time
// Support dynamic Thunderbolt AIC location in run time
// [Files]  		TbtOemBoard.h TbtOemBoard.c TbtOemLib.c TbtOemLib.h
// 
// 2     6/17/13 2:18a Barretlin
// [TAG]  		EIP126581
// [Category]  	Improvement
// [Description]  	add new AIC support setup item and change
// TBWakeupSupport name
// [Files]  		TbtOemBoard.h TbtOemBoard.c
// 
// 1     1/10/13 4:57a Barretlin
// Change SS path and update module for Thunderbolt Spec 1.6 for Cactus
// Ridge chip and Thunderbolt Spec 0.5 for Redwood Ridge chip
// 
// 12    12/12/12 4:14a Barretlin
// [TAG]  		EIP108272
// [Category]  	Spec Update
// [Severity]  	Important
// [Description]  	Update to Spec 1.4 to support Redwood Ridge chip
// [Files]  		TbtPei.c TbtSmm.c TbtDxe.c TbtDxe.sdl TbtGpe.asl
// TbtOemBoard.c TbtOemBoard.h TbtOemLib.c TbtOemLib.h
// 
// 11    10/28/12 11:50p Barretlin
// [TAG]  		EIP104870
// [Category]  	Spec Update
// [Severity]  	Important
// [Description]  	Change wake up flow for Spec 1.2 and Spec 1.3
// [Files]  		TbtPei.c TbtSmm.c TbtOemBoard.c TbtOemBoard.h
// TbtOemBoard.sdl TbtOemLib.c TbtOemLib.h
// 
// 10    10/28/12 11:21p Barretlin
// [TAG]  		EIP N/A
// [Category]  	Improvement
// [Description]  	Create new setup item for thunderbolt POC handling
// [Files]  		TbtOemBoard.c TbtOemBoard.h TbtSetup.sdl TbtSetup.sd
// TbtSetup.uni
// 
// 9     9/22/12 9:59a Barretlin
// [TAG]  		EIP N/A
// [Category]  	Improvement
// [Description]  	Use token to defien thunderbolt chip pins and update
// sample code
// [Files]  		TbtOemBoard.c TbtOemBoard.sdl
// 
// 8     8/20/12 5:12a Barretlin
// [TAG]  		EIP N/A
// [Category]  	Improvement
// [Description]  	Fix IO resource workaround broken in 4C 2port case
// [Files]  		TbtSmm.c TbtOemBoard.c TbtOemBoard.h TbtSetup.sdl
// TbtSetup.sd TbtSetup.uni
// 
// 7     8/17/12 8:44a Barretlin
// [TAG]  		EIP N/A
// [Category]  	Improvement
// [Description]  	Add IO resource workaround for Thunderbolt Spec1.1
// Because new spec has removed IO resource for Thunderbolt device
// [Files]  		TbtSmm.c TbtOemBoard.h TbtOemBoard.c TbtSetup.sdl
// TbtSetup.sd TbtSetup.uni 
// 
// 6     7/31/12 4:07a Barretlin
// [TAG]  		EIP96350
// [Category]  	Spec Update
// [Severity]  	Critical
// [Description]  	Updated Thunderbolt specification to version 1.00
// [Files]  		TbtDxe.c TbtSmm.c TbtOemBoard.c TbtOemBoard.h
// TbtOemBoard.sdl TbtSetup.sd TbtSetup.uni
// 
// 5     7/31/12 3:15a Barretlin
// [TAG]  		EIP91119
// [Category]  	Improvement
// [Description]  	Resolution for enable/disable Thunderbolt device option
// rom at POST time
// [Files]  		TbtDxe.c TbtOemBoard.c TbtOemBoard.h TbtOemBoard.sdl
// TbtSetup.sdl TbtSetup.sd TbtSetup.uni
// 
// 4     5/22/12 10:00a Barretlin
// [TAG]  		EIP90650
// [Category]  	Spec Update
// [Description]  	Specificatoin Update 0.94 - The default value of
// OPTIONAL workaround for devices that don't support surprise-removal
// should be disable.
// [Files]  		TbtSmm.c TbtOemBoard.c TbtOemBoard.h
// TbtSetup.sdl TbtSetup.sd TbtSetup.uni
// 
// 3     5/07/12 7:00a Barretlin
// [TAG]  		None
// [Category]  	Improvement
// [Description]  	Add three setup items for debug
// [Files]  		TbtDxe.c
// TbtGpe.asl
// TbtSmm.c
// TbtSetup.sd
// TbtSetup.uni
// TbtOemBoard.c
// TbtOemBoard.h
// 
// 2     2/20/12 12:01a Wesleychen
//  - Add new policy "SmiNotifyEnabled".
//  - Move OemProgramTbtSecurityLevel() to TbtDxe.c.
// 
// 1     12/08/11 4:09a Wesleychen
// Thunderbolt eModule initially releases.
// 
//*************************************************************************
#include <Efi.h>
#include <token.h>
#include <Setup.h>
#include <AmiLib.h>
#include <AmiDxeLib.h>
#include <AmiCspLib.h>
#include <TbtOemLib.h>
#include <TbtOemBoard.h>

// GUID Definition(s)
EFI_GUID  AmiTbtPlatformPpolicyGuid = AMI_TBT_PLATFROM_POLICY_PROTOCOL_GUID;
EFI_GUID  TbtHRStatusGuid           = AMI_TBT_HR_STATUS_GUID;
EFI_GUID  SetupGuid                 = SETUP_GUID;

// Variable Declaration(s)
AMI_TBT_PLATFORM_POLICY_PROTOCOL  gTbtPlatformPolicy;

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure:   TbtOemBoard_Init
//
// Description: This function is the entry point for TbtOemBoard.
//
// Input:       ImageHandle - Image handle
//              SystemTable - Pointer to the system table
//
// Output:      Return Status based on errors that occurred while waiting for
//              time to expire.
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TbtOemBoard_Init (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE *SystemTable )
{
    //
    // OEM Porting is required.
    //
    EFI_STATUS              Status             = EFI_SUCCESS;
    EFI_HANDLE              Handle             = NULL;
    UINTN                   VariableSize       = sizeof(SETUP_DATA);
    UINTN                   HRStatusSize       = sizeof(AMI_TBT_HR_STATUS_DATA);
    UINT32                  Attributes;
    UINT16                  counter;
    UINT8                   TbtSetVariableFlag = 0;
    CHAR16                  TbtHRStatusVar[]   = TBT_HR_STATUS_VARIABLE;
    AMI_TBT_HR_STATUS_DATA  HRStatusData;
    SETUP_DATA              SetupData;
    
    InitAmiLib(ImageHandle, SystemTable);
    
    //Initial Host Router information
    Status = pRS->GetVariable( L"TbtHRStatusVar", \
                               &TbtHRStatusGuid, \
                               NULL, \
                               &HRStatusSize, \
                               &HRStatusData );
    if (EFI_ERROR(Status)){
        TRACE((-1, "TbtOemBoard: Can not get Thunderbolt Host Router Information !!! \n"));
        HRStatusData.TbtHRStatus   = 0;
        //Get Thunderbolt host Series
        HRStatusData.TbtHRSeries = GetHRInfo();
        TRACE((-1, "TbtOemBoard: Thunderbolt Host Router Chip: %x \n", HRStatusData.TbtHRSeries));
        
        Status = pRS->SetVariable( TbtHRStatusVar, \
                                   &TbtHRStatusGuid, \
                                   EFI_VARIABLE_NON_VOLATILE | \
                                   EFI_VARIABLE_BOOTSERVICE_ACCESS | \
                                   EFI_VARIABLE_RUNTIME_ACCESS, \
                                   HRStatusSize, \
                                   &HRStatusData );
        if (!EFI_ERROR(Status))
            TRACE((-1, "TbtOemBoard: Create Thunderbolt Host Router Information !!! \n"));
    }
    
    Status = pRS->GetVariable( L"Setup", \
                               &SetupGuid, \
                               &Attributes, \
                               &VariableSize, \
                               &SetupData );
    ASSERT_EFI_ERROR (Status);
    
    Status = pBS->AllocatePool( \
                  EfiBootServicesData, \
                  sizeof(AMI_TBT_PLATFORM_POLICY_PROTOCOL), \
                  (VOID**)&gTbtPlatformPolicy );
    ASSERT_EFI_ERROR (Status);
    
    TRACE((-1, "TbtOemBoard: Start install Thunderbolt Platform Policy !!! \n"));
    pBS->SetMem( &gTbtPlatformPolicy, sizeof(AMI_TBT_PLATFORM_POLICY_PROTOCOL), 0 );
    
    //
    // OEM Porting required.
    //
/* Sample Code
    gTbtPlatformPolicy.TbtEnable             = SetupData.TbtEnable;
    gTbtPlatformPolicy.TbtGO2SX              = TBT_GO2SX;
    gTbtPlatformPolicy.TbtForcePWR           = TBT_ForcePWR;
    gTbtPlatformPolicy.TbtHotPlugEvt         = TBT_HotPlugEvt;
    gTbtPlatformPolicy.TbtOK2GO2SX_N         = TBT_OK2GO2SX_N;
    gTbtPlatformPolicy.CacheLineSize         = SetupData.TbtCacheLineSize;
    gTbtPlatformPolicy.TbtWakeupSupport      = SetupData.TbtWakeupSupport;
    gTbtPlatformPolicy.TbtAICSupport         = SetupData.TbtAICSupport;
    gTbtPlatformPolicy.TbtHandlePOC          = SetupData.TbtHandlePOC;
    gTbtPlatformPolicy.TbtSecurityLevel      = SetupData.TbtSecurityLevel;
    gTbtPlatformPolicy.Bus                   = TBT_UP_PORT_BUS;
    gTbtPlatformPolicy.Dev                   = TBT_UP_PORT_DEV;
    if (gTbtPlatformPolicy.TbtAICSupport == 1){
        if (SetupData.TbtHostLocation < 0x20){
            gTbtPlatformPolicy.Fun           = SetupData.TbtHostLocation;
        } else {
            gTbtPlatformPolicy.Dev           = 0x01;
            gTbtPlatformPolicy.Fun           = (SetupData.TbtHostLocation) - 0x20;
        }
    } else {
        gTbtPlatformPolicy.Fun               = TBT_UP_PORT_FUNC;
    }
    gTbtPlatformPolicy.ReserveMemoryPerSlot  = SetupData.ReserveMemoryPerSlot;
    gTbtPlatformPolicy.ReservePMemoryPerSlot = SetupData.ReservePMemoryPerSlot;
    gTbtPlatformPolicy.ReserveIOPerSlot      = SetupData.ReserveIOPerSlot;
    gTbtPlatformPolicy.SmiNotifyEnabled      = SetupData.SmiNotifyEnabled;
    gTbtPlatformPolicy.SwSmiEnabled          = SetupData.SwSmiEnabled;
    gTbtPlatformPolicy.NotifyEnabled         = SetupData.NotifyEnabled;
    gTbtPlatformPolicy.TbtOptionRom          = SetupData.TbtOptionRom;
    gTbtPlatformPolicy.TbtRmvReturnValue     = SetupData.TbtRmvReturnValue;
    gTbtPlatformPolicy.TbtIOresourceEnable   = SetupData.TbtIOresourceEnable;
    gTbtPlatformPolicy.TbtNVMversion         = SetupData.TbtNVMversion;

    Status = pBS->InstallProtocolInterface (
                            &Handle,
                            &AmiTbtPlatformPpolicyGuid,
                            EFI_NATIVE_INTERFACE,
                            &gTbtPlatformPolicy
                            );
    ASSERT_EFI_ERROR (Status);
//*/
    //synchronize Thunderbolt Host Router Information with Setup Data
    if (HRStatusData.TbtHRSeries != SetupData.TbtHRSeries){
        TRACE((-1, "TbtOemBoard: Setting Thunderbolt Host Router Information into Setup Data!!! \n"));
        SetupData.TbtHRSeries = HRStatusData.TbtHRSeries;
        TbtSetVariableFlag |= 1;
    }
    
#if defined TBT_INTEL_RC_CONFIG && TBT_INTEL_RC_CONFIG == 1
    if (gTbtPlatformPolicy.TbtEnable){
        if (gTbtPlatformPolicy.TbtAICSupport){
            if ((gTbtPlatformPolicy.Bus == 0) && (gTbtPlatformPolicy.Dev == 0x1C))
            {   // Thunderbolt AIC is at SB PCIE root port
                if ((SetupData.PcieMemRsvd[gTbtPlatformPolicy.Fun] != 353) || \
                    (SetupData.PcieMemRsvd[gTbtPlatformPolicy.Fun] != 737)){
                    // Change PCIE root port resource to correct location
                    SetupData.PcieRootPortEn[gTbtPlatformPolicy.Fun]    = 1;
                    SetupData.PcieRootPortHPE[gTbtPlatformPolicy.Fun]   = 1;
                    SetupData.ExtraBusRsvd[gTbtPlatformPolicy.Fun]      = TBT_DEFAULT_EXTRA_BUS_RESERVED;
                    SetupData.PcieMemRsvd[gTbtPlatformPolicy.Fun]       = TBT_DEFAULT_PCIE_MEM_RESERVED;
                    SetupData.PcieMemRsvdalig[gTbtPlatformPolicy.Fun]   = 26;
                    SetupData.PciePFMemRsvd[gTbtPlatformPolicy.Fun]     = TBT_DEFAULT_PCIE_PF_MEM_RESERVED;
                    SetupData.PciePFMemRsvdalig[gTbtPlatformPolicy.Fun] = 28;
                    SetupData.PcieIoRsvd[gTbtPlatformPolicy.Fun]        = TBT_DEFAULT_PCIE_IO_RESERVED;
                    
                    // Double check resource on other PCIE root port is disable
                    for(counter=0;counter<=7;counter++){
                        if(counter != gTbtPlatformPolicy.Fun){
                            if((SetupData.PcieMemRsvd[counter] == 353) || \
                               (SetupData.PcieMemRsvd[counter] == 737))
                            {
                                SetupData.PcieRootPortHPE[counter]      = 0;
                                SetupData.ExtraBusRsvd[counter]         = 0;
                                SetupData.PcieMemRsvd[counter]          = 10;
                                SetupData.PcieMemRsvdalig[counter]      = 1;
                                SetupData.PciePFMemRsvd[counter]        = 10;
                                SetupData.PciePFMemRsvdalig[counter]    = 1;
                                SetupData.PcieIoRsvd[counter]           = 4;
                            }
                        } // counter != gTbtPlatformPolicy.Fun
                    } // for loop
                    
                    TbtSetVariableFlag |= 1;
                } // PCIE root port resource is at incorrect location
            } else {
                // Thunderbolt AIC is at NB PCIE root port
                // Double check resource on other PCIE root port is disable
                for(counter=0;counter<=7;counter++){
                    if((SetupData.PcieMemRsvd[counter] == 353) || \
                       (SetupData.PcieMemRsvd[counter] == 737))
                    {
                        SetupData.PcieRootPortHPE[counter]      = 0;
                        SetupData.ExtraBusRsvd[counter]         = 0;
                        SetupData.PcieMemRsvd[counter]          = 10;
                        SetupData.PcieMemRsvdalig[counter]      = 1;
                        SetupData.PciePFMemRsvd[counter]        = 10;
                        SetupData.PciePFMemRsvdalig[counter]    = 1;
                        SetupData.PcieIoRsvd[counter]           = 4;

                        TbtSetVariableFlag |= 1;
                    }
                } // for loop
            }
        } else {
            if ((SetupData.PcieMemRsvd[TBT_UP_PORT_FUNC] != 353) || \
                (SetupData.PcieMemRsvd[TBT_UP_PORT_FUNC] != 737))
            {
                SetupData.TbtHostLocation                     = TBT_UP_PORT_FUNC;
                SetupData.PcieRootPortEn[TBT_UP_PORT_FUNC]    = 1;
                SetupData.PcieRootPortHPE[TBT_UP_PORT_FUNC]   = 1;
                SetupData.ExtraBusRsvd[TBT_UP_PORT_FUNC]      = TBT_DEFAULT_EXTRA_BUS_RESERVED;
                SetupData.PcieMemRsvd[TBT_UP_PORT_FUNC]       = TBT_DEFAULT_PCIE_MEM_RESERVED;
                SetupData.PcieMemRsvdalig[TBT_UP_PORT_FUNC]   = 26;
                SetupData.PciePFMemRsvd[TBT_UP_PORT_FUNC]     = TBT_DEFAULT_PCIE_PF_MEM_RESERVED;
                SetupData.PciePFMemRsvdalig[TBT_UP_PORT_FUNC] = 28;
                SetupData.PcieIoRsvd[TBT_UP_PORT_FUNC]        = TBT_DEFAULT_PCIE_IO_RESERVED;
                
                // Double check resource on other PCIE root port is disable
                for(counter=0;counter<=7;counter++){
                    if(counter != TBT_UP_PORT_FUNC){
                        if((SetupData.PcieMemRsvd[counter] == 353) || (SetupData.PcieMemRsvd[counter] == 737)){
                            SetupData.PcieRootPortHPE[counter]   = 0;
                            SetupData.ExtraBusRsvd[counter]      = 0;
                            SetupData.PcieMemRsvd[counter]       = 10;
                            SetupData.PcieMemRsvdalig[counter]   = 1;
                            SetupData.PciePFMemRsvd[counter]     = 10;
                            SetupData.PciePFMemRsvdalig[counter] = 1;
                            SetupData.PcieIoRsvd[counter]        = 4;
                        }
                    } // counter != TBT_UP_PORT_FUNC
                } // for loop
                
                TbtSetVariableFlag |= 1;
            } // PCIE root port resource is not at default location
        } // gTbtPlatformPolicy.TbtAICSupport
    } // gTbtPlatformPolicy.TbtEnable
#endif

  if (TbtSetVariableFlag != 0){
     Status = pRS->SetVariable( L"Setup", &SetupGuid, Attributes, 
                                VariableSize, &SetupData );
  }

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