summaryrefslogtreecommitdiff
path: root/Chipset/NB/GOP/IntelSaGopPolicy.c
blob: ccc3b8dae56764480c40d400580482befacf0ce9 (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
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (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/Chipset/Intel/NorthBridge/Haswell/IntelGopDriver/IntelSaGopPolicy.c 5     5/13/14 10:42p Dennisliu $
//
// $Revision: 5 $
//
// $Date: 5/13/14 10:42p $
//*************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/Chipset/Intel/NorthBridge/Haswell/IntelGopDriver/IntelSaGopPolicy.c $
// 
// 5     5/13/14 10:42p Dennisliu
// [TAG]           EIP167027
// [Category]      Improvement
// [Description]   [SharkBay Aptio4]Variable's attribute needs to be
// reviewed by SA component driver
// [Files]         NBDXEBoard.c; IntelSaGopSetup.c; IntelSaGopPolicy.c;
// NBDxe.c; NbPciCSP.c; PciHostBridge.c;
//
// 4     10/31/12 6:33a Jeffch
// [TAG]           None
// [Category]      Improvement
// [Description]  Add update GOP VBT address event.
//
// 3     8/14/12 5:42a Yurenlai
// [TAG]         None
// [Severity]    Important
// [Description] Implemented BIOS Integration Guide Rev 1.0 to Intel SA
// GOP driver.
// [Files]       IntelSaGopDriver.cif, IntelSaGopDriver.mak,
// IntelSaGopDriver.sdl,
//               IntelSaGopPolicy.c, IntelSaGopSetup.c, IntelSaGopSetup.h,
// IntelSaGopSetup.mak, IntelSaGopSetup.sd, IntelSaGopSetup.sdl,
//               IntelSaGopSetup.uni, IntelSaGopSwitch.c,
// IntelSaGopDriver.h,
//               NBPlatformData.h
//
// 2     7/27/12 7:42a Yurenlai
// [TAG]         None
// [Category]    Improvement
// [Description] Fix building error after update 4.6.5.4_Csm_OptOut_03.
// [Files]       IntelSaGopPolicy.c
//
// 1     3/08/12 10:54p Yurenlai
// [TAG]         None
// [Category]    Improvement
// [Description] Create Haswell Intel SA GOP Driver module part.
//               Notice : IntelGopDriver.efi and vbt.bin is dummy files.
//
//*************************************************************************
//<AMI_FHDR_START>
//
// Name:        IntelSaGopPolicy.c
//
// Description: This file initialises and Installs TerminalPlatformPolicy Protocol.
//
//<AMI_FHDR_END>
//**********************************************************************
#include <Token.h>
#include <AmiDxeLib.h>
#include <KscLib.h>
#include <Setup.h>
#include <AmiCspLib.h>
#include <Protocol\IntelSaGopDriver.h>
#include <Protocol\NBPlatformData.h>
#if defined(CsmOptOut_SUPPORT) && (CsmOptOut_SUPPORT == 1)
#include <AmiLoadCsmPolicy.h>
#endif
#define _SA_COMMON_DEFINITIONS_H_
#include <Protocol\SaPlatformPolicy\SaPlatformPolicy.h>

EFI_GUID  gPlatformGOPPolicyGuid = EFI_PLATFORM_GOP_POLICY_PROTOCOL_GUID;
EFI_GUID  gDxePlatformSaPolicyGuid = DXE_PLATFORM_SA_POLICY_GUID;
EFI_GUID  gSetupGuid = SETUP_GUID;
#if defined(CsmOptOut_SUPPORT) && (CsmOptOut_SUPPORT == 1)
EFI_GUID  gAmiOpromPolicyProtocolGuid = AMI_OPROM_POLICY_PROTOCOL_GUID;
EFI_GUID  gAmiLoadCsmGuid = AMI_LOAD_CSM_GUID;
#endif

PLATFORM_GOP_POLICY_PROTOCOL  mPlatformGOPPolicy;
DXE_PLATFORM_SA_POLICY_PROTOCOL        *gDxePlatformSaPolicy;
#if defined(CsmOptOut_SUPPORT) && (CsmOptOut_SUPPORT == 1)
AMI_OPROM_POLICY_PROTOCOL     *gAmiOpRomPolicyProtocol = NULL;
VOID *gInterface = NULL;
#endif
//
// Function implementations
//

EFI_STATUS
GetPlatformLidStatus (
   OUT LID_STATUS *CurrentLidStatus
)
{
#if defined CRB_EC_SUPPORT && CRB_EC_SUPPORT == 1
   EFI_STATUS              Status;
   UINT8                   PortDataOut;
   Status = InitializeKscLib ();

   if (Status == EFI_SUCCESS) {
     Status = SendKscCommand(KSC_C_READ_MEM);
     if (Status == EFI_SUCCESS) {
       Status = SendKscData(0x03);
       if (Status == EFI_SUCCESS) {
         Status = ReceiveKscData (&PortDataOut);
         if (Status == EFI_SUCCESS) {
           //
           // Bit6 = Lid State (1 = Open, 0 = Closed)
           //
           if ((PortDataOut & BIT6) >> 6)
             *CurrentLidStatus = LidOpen;
           else
             *CurrentLidStatus = LidClosed;
           return EFI_SUCCESS;
         }
       }
     }
   }
#endif

   return EFI_UNSUPPORTED;
}

EFI_STATUS
GetVbtData (
   OUT EFI_PHYSICAL_ADDRESS *VbtAddress,
   OUT UINT32 *VbtSize
)
{
  EFI_STATUS                    Status;
  UINTN                         FvProtocolCount;
  EFI_HANDLE                    *FvHandles;
#if (PI_SPECIFICATION_VERSION < 0x00010000)
  EFI_FIRMWARE_VOLUME_PROTOCOL  *Fv;
#else
  EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
#endif
  UINTN                         Index;
  UINT32                        AuthenticationStatus;
  EFI_FV_FILETYPE               FileType;
  EFI_FV_FILE_ATTRIBUTES        FileAttributes;

  UINT8                         *Buffer;
  UINTN                         VbtBufferSize;
  EFI_GUID  BmpImageGuid  = { 0x878AC2CC, 0x5343, 0x46F2, 0xB5, 0x63, 0x51, 0xF8, 0x9D, 0xAF, 0x56, 0xBA };

  Buffer          = NULL;
  FvHandles       = NULL;
  Status = pBS->LocateHandleBuffer (
                  ByProtocol,
                  #if (PI_SPECIFICATION_VERSION < 0x00010000)
                      &gEfiFirmwareVolumeProtocolGuid,
                  #else
                      &gEfiFirmwareVolume2ProtocolGuid,
                  #endif
                  NULL,
                  &FvProtocolCount,
                  &FvHandles
                  );
  if (!EFI_ERROR (Status)) {
    for (Index = 0; Index < FvProtocolCount; Index++) {
      Status = pBS->HandleProtocol (
                      FvHandles[Index],
                      #if (PI_SPECIFICATION_VERSION < 0x00010000)
                          &gEfiFirmwareVolumeProtocolGuid,
                      #else
                          &gEfiFirmwareVolume2ProtocolGuid,
                      #endif
                      (VOID **) &Fv
                      );

      Status = Fv->ReadFile (
                    Fv,
                    &BmpImageGuid,
                    &Buffer,
                    &VbtBufferSize,
                    &FileType,
                    &FileAttributes,
                    &AuthenticationStatus
                    );

      if (!EFI_ERROR (Status)) {
        *VbtAddress = (EFI_PHYSICAL_ADDRESS)Buffer;
        *VbtSize = (UINT32)VbtBufferSize;
        Status = EFI_SUCCESS;
        break;
      }
    }
  } else {
    Status = EFI_NOT_FOUND;
  }

  if (FvHandles != NULL) {
    pBS->FreePool (FvHandles);
    FvHandles = NULL;
  }

  return Status;
}

EFI_STATUS
GetPlatformDockStatus (
   OUT DOCK_STATUS CurrentDockStatus
)
{

  return EFI_UNSUPPORTED;
}

VOID IntelGopVbtUpdateNotify (
    IN EFI_EVENT        Event,
    IN VOID             *Context )
{
  EFI_STATUS  Status;
  EFI_PHYSICAL_ADDRESS          VbtAddress;
  UINT32                        VbtSize;

  Status = pBS->LocateProtocol (
                  &gDxePlatformSaPolicyGuid,
                  NULL,
                  (VOID **) &gDxePlatformSaPolicy
                  );
  if (!EFI_ERROR (Status)) {

   Status = GetVbtData(&VbtAddress, &VbtSize);
   if (!EFI_ERROR (Status)) {
      gDxePlatformSaPolicy->IgdConfig->VbtAddress = VbtAddress;
      gDxePlatformSaPolicy->IgdConfig->Size = VbtSize;
   }
  }
  // Kill event
  pBS->CloseEvent(Event);

}

EFI_STATUS
EFIAPI
IntelSaGopPolicyEntryPoint (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE *SystemTable
  )
/*++

Routine Description:

  Entry point for the Platform GOP Policy Driver.

Arguments:

  ImageHandle       Image handle of this driver.
  SystemTable       Global system service table.

Returns:

  EFI_SUCCESS           Initialization complete.
  EFI_OUT_OF_RESOURCES  Do not have enough resources to initialize the driver.

--*/
{
  EFI_STATUS  Status;
  NB_PLATFORM_DATA                NBPlatformData = {0};
  UINTN                           VariableSize;
  SETUP_DATA                      *SetupData = NULL;
  EFI_EVENT                       DxePlatformSaPolicyEvent;
  VOID                            *DxePlatformSaPolicyReg;
  UINT32                          Attributes = 0;   // [ EIP167027 ]


  InitAmiLib (ImageHandle, SystemTable);

  // Read the NB Platform Data
  VariableSize = sizeof (NB_PLATFORM_DATA);
  //Status = pRS->GetVariable (                 // [ EIP167027 ]
  //          L"NBPlatformData",
  //          &gSetupGuid,
  //          NULL,
  //          &VariableSize,
  //          &NBPlatformData
  //          );
  Status = pRS->GetVariable (
            L"NBPlatformData",
            &gSetupGuid,
            &Attributes,
            &VariableSize,
            &NBPlatformData
            );
  if (EFI_ERROR(Status))
    Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS;

  VariableSize = sizeof(SETUP_DATA);
  Status = GetEfiVariable(
                 L"Setup",
                 &gSetupGuid,
                 NULL,
                 &VariableSize,
                 &SetupData
                 );

#if (defined(CSM_SUPPORT) && (CSM_SUPPORT != 0))
#if defined(CsmOptOut_SUPPORT) && (CsmOptOut_SUPPORT == 1)

   Status = pBS->LocateProtocol( &gAmiLoadCsmGuid, \
                                 NULL, \
                                 &gInterface );
   if(!EFI_ERROR(Status))
   {
      if ((SetupData->VideoOpRom == 0) || (SetupData->VideoOpRom == 2)) return EFI_UNSUPPORTED;
   }

#else

#if defined(CORE_COMBINED_VERSION) && (CORE_COMBINED_VERSION <= 0x4028b)
{
 if ((SetupData->VideoOpRom) == 1) return EFI_UNSUPPORTED;
}
#else
 return EFI_UNSUPPORTED;
#endif // CORE_COMBINED_VERSION
#endif // CsmOptOut_SUPPORT
#endif // CSM_SUPPORT

  pBS->SetMem (&mPlatformGOPPolicy, sizeof (PLATFORM_GOP_POLICY_PROTOCOL), 0);

  mPlatformGOPPolicy.Revision                = PLATFORM_GOP_POLICY_PROTOCOL_REVISION_02;
  mPlatformGOPPolicy.GetPlatformLidStatus    = GetPlatformLidStatus;
  mPlatformGOPPolicy.GetVbtData              = GetVbtData;
  mPlatformGOPPolicy.GetPlatformDockStatus   = GetPlatformDockStatus;

  //
  // Install protocol to allow access to this Policy.
  //
  Status = pBS->InstallMultipleProtocolInterfaces (
                  &ImageHandle,
                  &gPlatformGOPPolicyGuid,
                  &mPlatformGOPPolicy,
                  NULL
                  );

  //NbSetupdata Pass to SaGlobalNvsArea.
  Status = pBS->CreateEvent (
                  EFI_EVENT_NOTIFY_SIGNAL,
                  TPL_CALLBACK,
                  IntelGopVbtUpdateNotify,
                  NULL,
                  &DxePlatformSaPolicyEvent
                  );

  if (!EFI_ERROR (Status)) {
    Status = pBS->RegisterProtocolNotify (
                    &gDxePlatformSaPolicyGuid,
                    DxePlatformSaPolicyEvent,
                    &DxePlatformSaPolicyReg
                    );
  }


  NBPlatformData.IGFXGopAvailable = 1;

  // Save SETUP variables.
  //Status = pRS->SetVariable (                 // [ EIP167027 ]
  //  L"NBPlatformData",
  //  &gSetupGuid,
  //  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
  //  sizeof (NB_PLATFORM_DATA),
  //  &NBPlatformData
  //  );
  Status = pRS->SetVariable (
    L"NBPlatformData",
    &gSetupGuid,
    Attributes,
    sizeof (NB_PLATFORM_DATA),
    &NBPlatformData
    );

  ASSERT_EFI_ERROR (Status);

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