summaryrefslogtreecommitdiff
path: root/Board/EM/SwitchableGraphics/SgTpv/MXM30/NBCIEfi.c
blob: eeaf2895a41b0a33810091ad8be6ae3d8386e80f (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
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (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/NBCIEfi.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/NBCIEfi.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
// 
//**********************************************************************
//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:		NBCIEfi.c
//
// Description:	This file installs 
//              Nbci EFI protocol
//
// 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\NBCI.h>

extern EFI_BOOT_SERVICES    *pBS;
extern EFI_RUNTIME_SERVICES *pRS;

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

EFI_STATUS NbciReturnSpecLevel (
    IN NBCI_EFI_PROTOCOL *This,
    IN OUT CHAR8        *pucRevisionLevel,
    OUT UINTN           *puSupportFuncs
);

EFI_STATUS NbciReturnStructure (
    IN NBCI_EFI_PROTOCOL *This,
    IN EFI_HANDLE       ControllerHandle,
    IN OUT CHAR16       usStructSize,
    IN CHAR16           usDataBlockID,
    OUT CHAR8           *pNbciStruct
);

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

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

NBCI_EFI_PROTOCOL   NBCIProtocol = {
    NbciReturnSpecLevel,
    NbciReturnStructure,
    NbciSelectOutputDevice,
    NbciCheckOutputDevice
};

// Auxilary Functions. Defined in Mxm30Efi.c
EFI_STATUS UpdateInt15MxmSISData (
    IN EFI_LEGACY_BIOS_PROTOCOL         *LegacyBiosProtocol
);

////////////////////////////////
// Nbci EFI PROTOCOL FUNCTIONS //
////////////////////////////////

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   NbciReturnSpecLevel
//
// 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:       
//              CHAR8       *pucRevisionLevel
//              UINTN       *puSupportFuncs
//
// 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' (NbciReturnStucture is also required)
//          Bit 2 = `1' if NbciSelectOutputDevice is supported, `0' if not
//          Bit 3 = `1' if NbciCheckOutputDevice is supported, `0' if not
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS NbciReturnSpecLevel (
    IN NBCI_EFI_PROTOCOL *This,
    IN OUT CHAR8       *pucRevisionLevel,
    OUT UINTN           *puSupportFuncs
){
    EFI_STATUS  Status = EFI_SUCCESS;

    *pucRevisionLevel = EFI_NBCI_DataBlockID;
    *puSupportFuncs = EFI_NBCI_SupportFuncs;

    return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   NbciReturnStructure
//
// Description: Caller provides expected Nbci Interface Revision Level and a pointer which, 
//              on return will contain the Nbci 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 Nbci 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 Nbci information structure, use usDataBlockID[0..7] to specify the revision
//          of the Nbci software specification that is supported by the Nbci 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 Nbci 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 NbciReturnStructure (
    IN NBCI_EFI_PROTOCOL *This,
    IN EFI_HANDLE       ControllerHandle,
    IN OUT CHAR16       *usStructSize,
    IN CHAR16           usDataBlockID,
    OUT CHAR8          **pNbciStruct
){
    EFI_STATUS  Status = EFI_SUCCESS;
// Only supports Rev 3.0
    if(usDataBlockID != EFI_NBCI_DataBlockID)
        return EFI_UNSUPPORTED;

    UpdateInt15MxmSISData(This);

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

    return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   NbciSelectOutputDevice
//
// 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 NbciSelectOutputDevice (
    IN NBCI_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:   NbciCheckOutputDevice
//
// 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 NbciCheckOutputDevice (
    IN NBCI_EFI_PROTOCOL *This,
    IN EFI_HANDLE       ControllerHandle,
    IN OUT CHAR16       usStructSize,
    IN EFI_HANDLE       ChildHandle,
    OUT CHAR8           ucDisplayAvailable
){

    return EFI_UNSUPPORTED;
}

///////////////////////////////////////
// END of Nbci EFI PROTOCOL FUNCTIONS //
///////////////////////////////////////

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   NBCIInterfaces
//
// Description: Common entry point to install:
// 1. Install Nbci protocol; 
//
// Input:       EFI_HANDLE           ImageHandle
//
// Output:      EFI_STATUS
//
// Modified:
//
// Referrals:
//
// Notes:
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
NBCIInterfaces (
    IN EFI_HANDLE         ImageHandle
)
{
    EFI_STATUS  Status;
    EFI_GUID  gEfiNBCIProtocolGuid = NBCI_EFI_GUID;

// Install NBCI_EFI_PROTOCOL
    Status = pBS->InstallProtocolInterface (
                &ImageHandle,
                &gEfiNbciProtocolGuid,
                EFI_NATIVE_INTERFACE,
                &NBCIProtocol
                );
    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                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************