summaryrefslogtreecommitdiff
path: root/Core/CSPLib/CspLibGeneric.h
blob: 0c24d1f64d7eed3db928666640620390bc70d257 (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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2008, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************

//**********************************************************************
//
// $Header: /Alaska/BIN/Chipset/Template/CSPLibrary/CspLibGeneric.h 6     11/12/11 6:39p Artems $
//
// $Revision: 6 $
//
// $Date: 11/12/11 6:39p $
//
//*****************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/Chipset/Template/CSPLibrary/CspLibGeneric.h $
// 
// 6     11/12/11 6:39p Artems
// Added functions for TopSwap functionality
// 
// 5     7/14/11 3:19p Artems
// EIP 64106: Updated source to be UEFI 2.3.1 and PI 1.2 compliant
// 
// 4     2/22/11 3:31p Artems
// EIP 51548 - Added AMI copyright headers, replaced TABs with spaces
// 
// 3     3/25/10 3:08p Artems
// EIP 33953: Added eLink infrastructure to support runtime shadow ram
// writing
// 
// 2     6/11/09 5:43p Robert
// Comment updates for CHM and coding standard
// 
// 1     10/13/07 11:29p Michaela
// Initial Checkin
// 
//
//*****************************************************************************


//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:        CspLibGeneric.h
//
// Description: This file contains generic code to add functionality that can 
//              be used by any module.
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>

#ifndef __CSP_LIB_GENERIC__H__
#define __CSP_LIB_GENERIC__H__
#ifdef __cplusplus
extern "C" {
#endif

#include <efi.h>
#include <pei.h>
#include <Protocol\PciRootBridgeIo.h>

#ifndef GUID_ZERO
#define GUID_ZERO \
{   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }
GUID_VARIABLE_DECLARATION(GuidZero, GUID_ZERO);
#endif


//<AMI_MHDR_START>
//----------------------------------------------------------------------------
// Name: AMI_TRACE
//
// Description:
//      This general-purpose, phase-independent macro allows debugging 
//      messages in code that is shared between PEI and DXE phases.
//
// Input:
//      Identical to TRACE (Type must be AMI_TRACE_ALWAYS)
//
// Notes:
//      For PEI phase, this macro assumes the identifier PeiServices is
//      defined.
//
//      The usage of this macro is identical to TRACE with the exception that
//      the type must always be AMI_TRACE_ALWAYS:
//
//        AMI_TRACE((AMI_TRACE_ALWAYS, "Hello World\n"));
//
//----------------------------------------------------------------------------
//<AMI_MHDR_END>

#if ( defined(TRACE) )
  #define AMI_TRACE(args) TRACE(args)
  #define AMI_TRACE_ALWAYS TRACE_ALWAYS
#elif ( defined(PEI_TRACE) )
  //------------------------------------------------------------------------
  // Generate a compiler message to help identify the build error if 
  // PeiServices is not defined in the calling function.
  //------------------------------------------------------------------------
  #pragma message("AMI_TRACE requires identifier definition: EFI_PEI_SERVICES **PeiServices")
  #define AMI_TRACE(args) PEI_TRACE(args)
  #define AMI_TRACE_ALWAYS TRACE_ALWAYS,PeiServices
#else
  #define AMI_TRACE(args)
  #define AMI_TRACE_ALWAYS
#endif


//<AMI_MHDR_START>
//----------------------------------------------------------------------------
// Name:    ABORT_ERROR
//
// Description: 
//      This phase-independent macro can be used to force premature
//      return from a function on error, displaying a message if possible and 
//      returning the EFI_STATUS value of the error.  (For compatibility, 
//      ABORT_CALL is also defined as a synonym for this macro.)
//
// Input:
//      arg - type must be EFI_STATUS
//
// Notes:
//      Use the macro with a function call to save screen/source file 
//      real estate:
//
//        ABORT_ERROR(FunctionCall(...));
//
//        The macro is replaced with the following:
//
//        {
//          EFI_STATUS Status = FunctionCall(...);
//          if (EFI_ERROR(Status)){
//              ...message with file name, line number and function name...
//              return Status;
//          }
//        }
//
//----------------------------------------------------------------------------
//<AMI_MHDR_END>

#define ABORT_ERROR(arg) { \
  EFI_STATUS Status = arg; \
  if ( EFI_ERROR( Status ) ) \
  { \
    AMI_TRACE((AMI_TRACE_ALWAYS, \
      "\n\nABORT Error in %s \nLine %i: %s\n\n\n",__FILE__, __LINE__, #arg)); \
    return Status; \
  } }
#ifndef ABORT_CALL
#define ABORT_CALL(arg) ABORT_ERROR(arg)
#endif


//<AMI_MHDR_START>
//----------------------------------------------------------------------------
// Name:    ABORT_ERROR_STATUS
//
// Description:
//      This phase-independent macro can be used to force premature
//      return from a function on error, displaying a message if possible and
//      returning the caller-specified value in the event of an error.    
//      (For compatibility, ABORT_CALL_STATUS is also defined as a 
//      synonym for this macro.)
//
// Input: 
//      status - value to return (no type constraint)
//      arg    - type must be EFI_STATUS
//
// Notes:
//      Use the macro with a function call to save screen/source file 
//      real estate (note: the return value is discarded):
//
//        ABORT_ERROR_STATUS(MyErrorValue, FunctionCall(...));
//
//        The macro is replaced with the following:
//
//        {
//          if (EFI_ERROR( FunctionCall(...) ) ){
//            ...message with file name, line number and function name...
//            return MyErrorValue;
//          }
//        }
//
//----------------------------------------------------------------------------
//<AMI_MHDR_END>

#define ABORT_ERROR_STATUS(retval, arg) { \
  if ( EFI_ERROR(arg) ) \
  { \
    AMI_TRACE((AMI_TRACE_ALWAYS, \
      "\n\nABORT Error in %s \nLine %i: %s\n\n\n",__FILE__, __LINE__, #arg)); \
    return (retval); \
  } }
#ifndef ABORT_CALL_STATUS
#define ABORT_CALL_STATUS(retval, arg) ABORT_ERROR_STATUS(retval, arg)
#endif


//<AMI_MHDR_START>
//----------------------------------------------------------------------------
// Name:    STOP_ERROR
//
// Description: 
//      This phase-independent macro can be used to force an infinite loop 
//      on error, ensuring execution does not continue past the error and
//      easing the burden of locating the source of the error.  A message is
//      displayed if possible.  (For compatibility, ASSERT_CALL is 
//      also defined as a synonym for this macro.)
//
// Input: 
//      arg - type must be EFI_STATUS
//
// Notes:
//      Use the macro with a function call to save screen/source file 
//      real estate (note: the return value is discarded):
//
//        STOP_ERROR(FunctionCall(...));
//
//        The macro is replaced with the following:
//
//        {
//          if (EFI_ERROR(FunctionCall(...))){
//            ...message with file name, line number and function name...
//            EFI_DEADLOOP();
//          }
//        }
//
//----------------------------------------------------------------------------
//<AMI_MHDR_END>

#define STOP_ERROR(arg) { \
  if ( EFI_ERROR( arg ) ) { \
    AMI_TRACE((AMI_TRACE_ALWAYS, \
      "\n\nSTOP Error in %s \nLine %i: %s\n",__FILE__, __LINE__,#arg)); \
    EFI_DEADLOOP(); \
  } }
#ifndef ASSERT_CALL
#define ASSERT_CALL(arg) STOP_ERROR(arg)
#endif


//----------------------------------------------------------------------------
// LocateMultiplePpi types/declarations

//<AMI_THDR_START>
//------------------------------------------------------------------
//
// Name:        PPI_LOCATE_STRUCT
//
// Fields:      Type    ParameterName    Description
//------------------------------------------------------------------
//  EFI_GUID  Guid - GUID_ZERO or value of Guid
//  EFI_GUID *GuidPtr - NULL or pointer to Guid
//  UINTN Instance - Instance Number to discover
//  EFI_PEI_PPI_DESCRIPTOR **Descriptor - Pointer to a Pointer to reference the found descriptor. If not NULL, returns a pointer to the descriptor (includes flags, etc)
//  VOID **Ptr - Pointer to be updated with an instance of a pointer to a pointer of the PPI being located
//
// Description: 
//  This data structure contains the information that is used to 
//  make a call to LocatePpi and return the needed pointers
//
// Notes:   
//      
//------------------------------------------------------------------
//<AMI_THDR_END>
typedef struct {                            
    EFI_GUID                    Guid;       // GUID_ZERO or value of Guid
    EFI_GUID                    *GuidPtr;   // NULL or pointer to Guid
    UINTN                       Instance;
    EFI_PEI_PPI_DESCRIPTOR      **Descriptor;
    VOID                        **Ptr;
} PPI_LOCATE_STRUCT;

EFI_STATUS  LocateMultiplePpi (
    EFI_PEI_SERVICES    **PeiServices,
    UINT32              PpiTableSize,
    PPI_LOCATE_STRUCT   *Ppi
);


//----------------------------------------------------------------------------
// LocateMultipleProtocol types/declarations

//<AMI_THDR_START>
//------------------------------------------------------------------
//
// Name:        PROTOCOL_LOCATE_STRUCT
//
// Fields:      Type    ParameterName    Description
//------------------------------------------------------------------
//  EFI_GUID  Guid - GUID_ZERO or value of Guid
//  EFI_GUID *GuidPtr - NULL or pointer to Guid
//  VOID *Registration - Optional Registration Key returned from RegisterProtocolNotify() 
//  VOID **Interface - Pointer to be updated with an instance of a pointer to a pointer of the Protocol being located
//
// Description: 
//  This data structure contains the information that is used to 
//  make a call to LocateProtocol and return the needed pointers
//
// Notes:   
//      
//------------------------------------------------------------------
//<AMI_THDR_END>
typedef struct {                            
    EFI_GUID                    Guid;       // GUID_ZERO or value of Guid
    EFI_GUID                    *GuidPtr;   // NULL or pointer to Guid
    VOID                        *Registration;
    VOID                        **Interface;
} PROTOCOL_LOCATE_STRUCT;

EFI_STATUS  LocateMultipleProtocol (
    EFI_BOOT_SERVICES           *pBS,
    UINT32                      ProtocolTableSize,
    PROTOCOL_LOCATE_STRUCT      *Protocol
);


//----------------------------------------------------------------------------
// PEI PCI Access related types/declarations

//<AMI_THDR_START>
//------------------------------------------------------------------
//
// Name:        PEI_PCI_ARGS
//
// Fields:      Type    ParameterName    Description
//------------------------------------------------------------------
//  EFI_PEI_SERVICES **PeiServices - instance of the PEI Services Table
//  EFI_PEI_PCI_CFG_PPI *Cfg - OPTIONAL Pointer to an Instance of the PciCfg PPI
//  EFI_PEI_PCI_CFG_PPI_WIDTH Width - Width of the data to be accessed in the PCI space
//  UINT32 Address - (B/D/F/R) PCI address of the device to read from
//  VOID *Value - Buffer to store Data to Write or Data that is read
//
// Description: 
//  This data structure contains the information that is used to 
//  read or write to PCI Devices using the PEI PciCfg PPI
//
// Notes:   
//      
//------------------------------------------------------------------
//<AMI_THDR_END>
typedef struct {
    EFI_PEI_SERVICES            **PeiServices;
    EFI_PEI_PCI_CFG2_PPI         *Cfg;
    EFI_PEI_PCI_CFG_PPI_WIDTH   Width;
    UINT32                      Address;        // PEI phase uses 32-bit addresses
    VOID                        *Value;
} PEI_PCI_ARGS;

EFI_STATUS 
PeiWritePci (  
    PEI_PCI_ARGS     *Pci
);

EFI_STATUS  
PeiReadPci(  
    PEI_PCI_ARGS     *Pci
);


//----------------------------------------------------------------------------
// DXE PCI Access related related types/declarations

//<AMI_THDR_START>
//------------------------------------------------------------------
//
// Name:        RTBRG_PCI_ARGS
//
// Fields:      Type    ParameterName    Description
//------------------------------------------------------------------
//  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *RtBrdg - Pointer to an instance of the DXE PCI Root Bridge Protocol
//  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width - Width of the data to read from or write to the PCI Device
//  UINT64 Address - PCI Address of the Device to read from or write to
//  UINTN Count - Number of times to repeat the Read or write command
//  VOID *Buffer - Buffer to store Data to Write or Data that is read
//
// Description: 
//  This data structure contains the information that is used to 
//  read or write to PCI Devices using the DXE PCI Root Bridge Protocol
//
// Notes:   
//      
//------------------------------------------------------------------
//<AMI_THDR_END>
typedef struct {
    IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL          *RtBrdg;
    IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH    Width;
    IN UINT64                                   Address;
    IN UINTN                                    Count;
    IN OUT VOID                                 *Buffer;
} RTBRG_PCI_ARGS;

EFI_STATUS RbReadPci (
    RTBRG_PCI_ARGS  *Arg
);

EFI_STATUS RbWritePci (
    RTBRG_PCI_ARGS  *Arg
);

VOID OemRuntimeShadowRamWrite(
    IN BOOLEAN Enable
);


#define SB_BACKED_UP_CONTROL_REGISTER 0x3414

BOOLEAN IsTopSwapOn(
    VOID
);

VOID SetTopSwap(
    IN BOOLEAN On
);

/****** DO NOT WRITE BELOW THIS LINE *******/
#ifdef __cplusplus
}
#endif
#endif

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