summaryrefslogtreecommitdiff
path: root/Board/EM/SwitchableGraphics/SgTpv/MXM30/Mxm30Efi.c
blob: b0aa2071ca2b00949db70f97a9697ce685b28553 (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
416
417
418
419
420
421
422
423
424
425
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (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/Sg nVidia API/Mxm30Efi.c 2     9/09/12 11:12p Joshchou $
//
// $Revision: 2 $
//
// $Date: 9/09/12 11:12p $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/SwitchableGraphics/Sg TPV/Sg nVidia API/Mxm30Efi.c $
// 
// 2     9/09/12 11:12p Joshchou
// [TAG]  		None
// [Category]  	Improvement
// [Description]  	Tpv module support for sharkbay.
// [Files]  		MXM30.mak
// Mxm30Dxe.dxs
// Mxm30Dxe.c
// Mxm30Efi.c
// NBCIEfi.c
// MxmInt15.asm
// MXM30.cif
// 
// 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]  		MXM30.cif
// MXM30.sdl
// MXM30.mak
// Mxm30Dxe.dxs
// Mxm30Dxe.c
// Mxm30Efi.c
// NBCIEfi.c
// MxmInt15.asm
// Mxm30ElkCreek4.mxm
// Mxm30ElkCreekIII.mxm
// 
// 
// 1     9/17/10 1:16p 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]	
//         Mxm30.cif;*.sdl;*.mak;
//         Mxm30Dxe.c;*.dxs 
//         Mxm30efi.c
//         MxmInt15.asm
//         NbciEfi.c
//         Mxm30ElkCreek3(4).mxm
// 
// 1     6/08/10 3:43p Alexp
// 
//**********************************************************************
//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:		Mxm30Efi.c
//
// Description:	This file installs 
//              1)Mxm EFI protocol
//              2)Mxm Legacy Int15 and 
//              3)Acpi interfaces for Switchable Graphics
//
// Notes:		MAKE SURE NO PEI OR DXE SPECIFIC CODE IS NEEDED
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>
#include <Token.h>
#include <AmiDxeLib.h>
#include <DXE.h>

#include <Protocol\Mxm30.h>

extern EFI_BOOT_SERVICES    *pBS;
extern EFI_RUNTIME_SERVICES *pRS;

// Defined in Mxm30Dxe.c
extern VOID                 *gMxmLegMemAddr;
extern UINTN                gMxmLegMemSize;
/////////////////////////////////////////
//     MXM EFI PROTOCOL PROTOTYPES     //
/////////////////////////////////////////

EFI_STATUS MxmReturnSpecLevel (
    IN MXM3_EFI_PROTOCOL *This,
    IN EFI_HANDLE       ControllerHandle,
    IN OUT CHAR16       usStructSize,
    IN OUT CHAR8        *pucRevisionLevel,
    OUT UINTN           *puSupportFuncs
);

EFI_STATUS MxmReturnStructure (
    IN MXM3_EFI_PROTOCOL *This,
    IN EFI_HANDLE       ControllerHandle,
    IN OUT CHAR16       *usStructSize,
    IN CHAR16           usDataBlockID,
    OUT CHAR8           **pMxmStruct
);

EFI_STATUS MxmSelectOutputDevice (
    IN MXM3_EFI_PROTOCOL *This,
    IN EFI_HANDLE      ControllerHandle,
    IN OUT CHAR16      usStructSize,
    IN EFI_HANDLE      ChildHandle,
    IN CHAR8           ucOutputSetting
);

EFI_STATUS MxmCheckOutputDevice (
    IN MXM3_EFI_PROTOCOL *This,
    IN EFI_HANDLE       ControllerHandle,
    IN OUT CHAR16       usStructSize,
    IN EFI_HANDLE       ChildHandle,
    OUT CHAR8           ucDisplayAvailable
);

MXM3_EFI_PROTOCOL   Mxm30Protocol = {
    MxmReturnSpecLevel,
    MxmReturnStructure,
    MxmSelectOutputDevice,
    MxmCheckOutputDevice
};

////////////////////////////////
// MXM EFI PROTOCOL FUNCTIONS //
////////////////////////////////

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   MxmReturnSpecLevel
//
// Description: Caller provides pointer to location, which on call contains the Module requested Spec Revision
//              Level, and which on exit, will contain the Platform's preferred Revision Level and Bit Field of
//              supported functions.
//
// Input:       UINT8       *This
//              EFI_HANDLE   ControllerHandle
//              UCHAR16     usStructSize
//
// Output:      EFI_STATUS =
//              EFI_SUCCESS, EFI_UNSUPPORTED, EFI_INVALID_PARAMETER, EFI_BUFFER_TOO_SMALL
//
// Modified:
//
// Referrals:
//
// Notes:
//          Where the integer value passed in uSupportFuncs indicates supported functions:
//          Bit 0 = `1' (this method is required)
//          Bit 1 = `1' (MxmReturnStucture is also required)
//          Bit 2 = `1' if MxmSelectOutputDevice is supported, `0' if not
//          Bit 3 = `1' if MxmCheckOutputDevice is supported, `0' if not
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS MxmReturnSpecLevel (
    IN MXM3_EFI_PROTOCOL *This,
    IN EFI_HANDLE       ControllerHandle,
    IN OUT CHAR16      usStructSize,
    IN OUT CHAR8       *pucRevisionLevel,
    OUT UINTN           *puSupportFuncs
){
    EFI_STATUS  Status = EFI_SUCCESS;

    *pucRevisionLevel = EFI30_DataBlockID;
    *puSupportFuncs = EFI30_SupportFuncs;

    return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   MxmReturnStructure
//
// Description: Caller provides expected MXM Interface Revision Level and a pointer which, 
//              on return will contain the MXM structure.
//
// Input:       UINT8       *This
//              EFI_HANDLE   ControllerHandle
//              UCHAR16     usStructSize
//
// Output:      EFI_STATUS =
//              EFI_SUCCESS, EFI_UNSUPPORTED, EFI_INVALID_PARAMETER, EFI_BUFFER_TOO_SMALL
//
// Modified:
//
// Referrals:
//
// Notes:
//       ControllerHandle - used to differentiate which MXM module is being referenced. 
//          This is the EFI handle for the PCI device. ChildHandle where used, is the output device (the display).
//       usStructSize - set to the size of the supplied buffer by the caller, and on return should contain the
//          actual size of the structure. If the structure is larger than the buffer, EFI_BUFFER_TOO_SMALL
//          should be returned as the status of the call
//      usDataBlockID - Identifier for the data block to return. To obtain the MXM information structure, use usDataBlockID[0..7] to specify the revision
//          of the MXM software specification that is supported by the MXM module.Format is binary coded decimal, for example: 0030h = 3.0, etc.
//          To obtain an additional vendor specific data block, use lower 8 bits to specify an identifier in the range 0x80-0x8F. 
//          If the system BIOS does not contain MXM Graphics Module Software Specification Version 3.0 such a data block, it should return an error. 
//          Graphics vendors should not assume a specific assignment within this range - the SBIOS can store
//          the data for different vendors in any order in the 0x80-0x8F identifier range
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS MxmReturnStructure (
    IN MXM3_EFI_PROTOCOL *This,
    IN EFI_HANDLE       ControllerHandle,
    IN OUT CHAR16       *usStructSize,
    IN CHAR16           usDataBlockID,
    OUT CHAR8          **pMxmStruct
){
    EFI_STATUS  Status = EFI_SUCCESS;
// Only supports Rev 3.0
    if(usDataBlockID != EFI30_DataBlockID)
        return EFI_UNSUPPORTED;

// TO DO: calculate the offset within *pMxmStruct by comparing the DevID in the MXM Header with given controller handle DevID
    *pMxmStruct = gMxmLegMemAddr;
    *usStructSize = (CHAR16)gMxmLegMemSize;

    return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   MxmSelectOutputDevice
//
// Description: Select Output Device Channel. 
//              Caller provides the handle of the target adapter, the handle of the display and the output setting
//
// Input:       UINT8       *This
//              EFI_HANDLE   ControllerHandle
//              UCHAR16     usStructSize
//
// Output:      EFI_STATUS =
//              EFI_SUCCESS, EFI_UNSUPPORTED, EFI_INVALID_PARAMETER, EFI_BUFFER_TOO_SMALL
//
// Modified:
//
// Referrals:
//
// Notes:
//              Where the value passed in ucOutputSetting may indicate one of the following actions:
//              0 - Acquire shared Display DDC
//              1 - Enable this Display Output
//              3 - Enable this Display - Both Output and DDC
//              4 - Release shared Display DDC
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS MxmSelectOutputDevice (
    IN MXM3_EFI_PROTOCOL *This,
    IN EFI_HANDLE      ControllerHandle,
    IN OUT CHAR16      usStructSize,
    IN EFI_HANDLE      ChildHandle,
    IN CHAR8           ucOutputSetting
){

    return EFI_UNSUPPORTED;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   MxmCheckOutputDevice
//
// Description: Check Availability of Output Device. Caller provides the handle of 
//              the target adapter and the handle of the display
//
// Input:       UINT8       *This
//              EFI_HANDLE   ControllerHandle
//              UCHAR16     usStructSize
//
// Output:      EFI_STATUS =
//              EFI_SUCCESS, EFI_UNSUPPORTED, EFI_INVALID_PARAMETER, EFI_BUFFER_TOO_SMALL
//              UCHAR8 ucDisplayAvailable
//
// Modified:
//
// Referrals:
//
// Notes:   The returned value ucDisplayAvailable will be one of the following values:
//          0 - Connector is currently available
//          1 - Connector is not currently available
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS MxmCheckOutputDevice (
    IN MXM3_EFI_PROTOCOL *This,
    IN EFI_HANDLE       ControllerHandle,
    IN OUT CHAR16       usStructSize,
    IN EFI_HANDLE       ChildHandle,
    OUT CHAR8           ucDisplayAvailable
){

    return EFI_UNSUPPORTED;
}

///////////////////////////////////////
// END of MXM EFI PROTOCOL FUNCTIONS //
///////////////////////////////////////

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:    LoadFile
//
// Description:    Reads the file with the given GUID.
//
// Input:        
//        IN EFI_GUID     *Guid,
//        IN VOID         **Buffer
//        IN UINTN        *BufferSize
//                
// Output:        
//      EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS LoadFile(
    EFI_GUID        *Guid,
    VOID            **Buffer,
    UINTN            *BufferSize
)
{
    EFI_STATUS                        Status;
    UINTN                            NumHandles;
    EFI_HANDLE                        *HandleBuffer;
    EFI_FIRMWARE_VOLUME_PROTOCOL    *Fv;
    UINT32                            FvStatus;
    UINTN                            i;
    EFI_GUID    EfiFVProtocolGuid = EFI_FIRMWARE_VOLUME_PROTOCOL_GUID;

    *Buffer = 0;
    *BufferSize = 0;

    Status = pBS->LocateHandleBuffer(ByProtocol,&EfiFVProtocolGuid,NULL,&NumHandles,&HandleBuffer);
    if (EFI_ERROR(Status)) return Status;

    for (i = 0; i < NumHandles; ++i) {
        Status = pBS->HandleProtocol(HandleBuffer[i],&EfiFVProtocolGuid,&Fv);
        if (EFI_ERROR(Status)) continue;
        Status = Fv->ReadSection(Fv,Guid,EFI_SECTION_RAW,0,Buffer,BufferSize,&FvStatus);
        if (Status == EFI_SUCCESS) break;
    }

    pBS->FreePool(HandleBuffer);
    return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   MXM30Interfaces
//
// Description: Entry point of EFI MXM Support driver. The function istalls 
// 1. Install MXM protocol; 
// 2. Update data structure to be passed to Int15 binary
//      must support multiple MXM data modules. Dependent on controller's handle
//  Load MXM data block <1Mb area.
//      a. Copy MXM Structure below 1MB
//          1. Allocate Legacy mem space for MXM dat <1MB
//          OR          
//          2. Update the MXM data by the pointer returned by Int15 5F80 Func01(default)
//      b. Update the pointer to MXM data in EFI Protocol API
//      c. Create an ACPI SSDT table and copy MXM block there (ASL MXM logic must handle different MXM modules...)
//
// Input:       EFI_HANDLE           ImageHandle,
//              EFI_SYSTEM_TABLE     *SystemTable
//
// Output:      EFI_STATUS
//
// Modified:
//
// Referrals:
//
// Notes:
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
MXM30Interfaces (
    IN EFI_HANDLE         ImageHandle,
    IN EFI_SYSTEM_TABLE   *SystemTable
)
{
    EFI_STATUS  Status;
    EFI_GUID  gEfiMxm3ProtocolGuid = MXM3_EFI_GUID;

    Status = pBS->InstallProtocolInterface (
                &ImageHandle,
                &gEfiMxm3ProtocolGuid,
                EFI_NATIVE_INTERFACE,
                &Mxm30Protocol
                );
    ASSERT_EFI_ERROR (Status);

    return Status;
}


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