summaryrefslogtreecommitdiff
path: root/Board/EM/SwitchableGraphics/SgTpv/SgTpvDxe.c
blob: d3f8465770462121b5d2d63fbc223b38c2839ad4 (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
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2012, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**        5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093         **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************
//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/SwitchableGraphics/Sg TPV/SgTpvDxe.c 4     5/13/14 4:44a Joshchou $
//
// $Revision: 4 $
//
// $Date: 5/13/14 4:44a $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/SwitchableGraphics/Sg TPV/SgTpvDxe.c $
// 
// 4     5/13/14 4:44a Joshchou
// [TAG]  		EIP167034
// [Category]  	Improvement
// [Description]  	Review the variable's attribute.
// 
// 3     1/15/13 5:02a Joshchou
// [TAG]  		EIP107237
// [Category]  	New Feature
// [Description]  	Support SG function on ULT platform.
// 
// 2     9/09/12 11:15p Joshchou
// [TAG]  		EIPNone
// [Category]  	New Feature
// [Description]  	Tpv module support for sharkbay.
// [Files]  		SgTpv.sdl
// SgTpv.mak
// SgTpvPei.c
// SgTpvPei.dxs
// SgTpvDxe.c
// SgTpvDxe.dxs
// SgTpv.cif
// 
// 2     12/06/11 2:15a Alanlin
// [TAG]  		EIP76248
// [Category]  	New Feature
// [Description]  	PX 5.0 feature updated 
// 
// 1     6/27/11 5:25a Alanlin
// [TAG]  		EIP61848
// [Category]  	New Feature
// [Description]  	Initial check-in.Integrated SwitchableGraphics Intel
// Reference code 0.6.0
// [Files]  		SgTpv.cif
// SgTpv.sdl
// SgTpv.mak
// SgTpvPei.c
// SgTpvPei.dxs
// SgTpvDxe.c
// SgTpvDxe.dxs
// 
// 
// 2     9/24/10 5:37p Alexp
//  [TAG]    	  EIP43103 --> fix CPU exception error by checking if
// endpoint bus is enabled in PEG root bridge
// 
// 1     9/17/10 1:12p Alexp
// [TAG]    	  EIP43103 
// [Category]  Function Request
// [Severity]	  Normal
// [Symptom]    Initial check-in of SgTPV module
// [RootCause] Request to implement SG reference code .
// [Solution]	Initial check-in. 
// [Files]	
//         SgTpv.cif;*.sdl;*.mak;
//         SgTpvPei.c;*.dxs;
//         SgTpvDxe.c;*.dxs  
// 
// 2     6/16/10 5:07p Alexp
// 
// 1     6/10/10 4:22p Alexp
// 
// 
//**********************************************************************
//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:		SgTpvDXE.c
//
// Description:	This file contains the etry point of SgTpv Support driver
//
// Notes:		MAKE SURE NO PEI OR DXE SPECIFIC CODE IS NEEDED
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>
//
// 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 "EfiScriptLib.h"
#endif

#include <Token.h>
#include <SetupDataDefinition.h>
#include "SaAccess.h"

#include "CpuRegs.h"
#include "CpuPlatformLib.h"
#include "PchRegsPcie.h"

#include EFI_PROTOCOL_PRODUCER (SaPlatformPolicy)

#define AMD_VID     0x1002
#define NVIDIA_VID  0x10DE
#define SETUP_GUID { 0xEC87D643, 0xEBA4, 0x4BB5, 0xA1, 0xE5, 0x3F, 0x3E, 0x36, 0xB2, 0x0D, 0xA9 }
SETUP_DATA    SetupDataBuffer;
CPU_FAMILY            CpuFamilyId;

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   SgTpvDxeEntryPoint
//
// Description: Entry point of EFI SG Support driver.
//
// Input:       EFI_HANDLE           ImageHandle,
//              EFI_SYSTEM_TABLE     *SystemTable
//
// Output:      EFI_STATUS
//
// Modified:
//
// Referrals:
//
// Notes:
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
SgTpvDxeEntryPoint (
    IN EFI_HANDLE         ImageHandle,
    IN EFI_SYSTEM_TABLE   *SystemTable
)
{
    EFI_STATUS                      Status;
    DXE_PLATFORM_SA_POLICY_PROTOCOL *DxePlatformSaPolicy;
    UINT8                           EndpointBus;
    EFI_GUID                        gSetupGuid = SETUP_GUID; 
    UINTN                           VariableSize = 0;
    UINT8                 RootPortDev;
    UINT8                 RootPortFun;
    UINT32                          Attributes = 0;

    
    EfiInitializeDriverLib (ImageHandle, SystemTable);
    CpuFamilyId = GetCpuFamily();
    //
    // Locate the SG Policy Protocol
    //
    Status = gBS->LocateProtocol (
                  &gDxePlatformSaPolicyGuid,
                  NULL,
                  &DxePlatformSaPolicy
                  );
    if (EFI_ERROR (Status)) {
    return Status;
    }
    
    //
    // Update SG DXE Policy -
    //

    // 1 = Load secondary display device VBIOS; 0 = Do not load
    //
    DxePlatformSaPolicy->VbiosConfig->LoadVbios = LOADVBIOS;
    DxePlatformSaPolicy->VbiosConfig->VbiosSource = VBIOSSOURCE;
    DxePlatformSaPolicy->VbiosConfig->ExecuteVbios = EXECUTEVBIOS;
#if (defined(SGOEMSSDT_SUPPORT) && (SGOEMSSDT_SUPPORT != 0))
    DxePlatformSaPolicy->VbiosConfig->ExecuteVbios = 0;
#endif

    //
    //  Endpoint Base Addresses and Capability Structure Offsets for ASL usage
    //

    if (CpuFamilyId == EnumCpuHswUlt) {
      /// For SwitchableGraphics support the dGPU is present on PCH RootPort
      RootPortDev = PCI_DEVICE_NUMBER_PCH_PCIE_ROOT_PORTS;
      RootPortFun = SG_ULT_PORT_FUNC;
     } else {
      /// Assume: For SwitchableGraphics support the dGPU is present on PEG RootPort by default
      RootPortDev = SA_PEG10_DEV_NUM;
      RootPortFun = SA_PEG10_FUN_NUM;
     }

    //EndpointBus  = McD1PciCfg8 (PCI_SBUS);
    EndpointBus = MmPci8 (0, 0, RootPortDev, RootPortFun, PCI_SBUS);

    if (EndpointBus != 0xff && 
        McDevFunPciCfg16 (EndpointBus, 0, 0, PCI_VID) == NVIDIA_VID) 
    {
        DxePlatformSaPolicy->VbiosConfig->ExecuteVbios = 0;
    }

    VariableSize  = sizeof (SETUP_DATA);
    Status = gRT->GetVariable (
      L"Setup",
      &gSetupGuid,
      &Attributes,
      &VariableSize,
      &SetupDataBuffer
    );
    DEBUG ((EFI_D_ERROR, "SgTpvDxeEntryPoint Attributes = %x\n",Attributes));

  
#if (defined(CSM_SUPPORT) && (CSM_SUPPORT != 0))
 #if defined(CsmOptOut_SUPPORT) && (CsmOptOut_SUPPORT == 1)
    if ((SetupDataBuffer.CsmLaunchPolicy == 0) || (SetupDataBuffer.BootOptionFilter == 2))
        {DxePlatformSaPolicy->VbiosConfig->ExecuteVbios = 0;}
 #endif
#else
        DxePlatformSaPolicy->VbiosConfig->ExecuteVbios = 0;
#endif 
//    if (SetupDataBuffer.PrimaryDisplay == 4)
//    {
      if (EndpointBus != 0xff && 
          McDevFunPciCfg16 (EndpointBus, 0, 0, PCI_VID) == AMD_VID) 
      {
          SetupDataBuffer.TPVCardCheck = 1;
      } else
          SetupDataBuffer.TPVCardCheck = 0;

      Status = gRT->SetVariable (
                              L"Setup",
                              &gSetupGuid,
                              Attributes,
                              sizeof(SETUP_DATA),
                              &SetupDataBuffer
      );
//    } // SetupDataBuffer.PrimaryDisplay == 4

    return Status;
}

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