summaryrefslogtreecommitdiff
path: root/Core/CSPLib/CspLibPei.C
blob: 50a83a1779a6ed0d54712a60be9d631ffd807b28 (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
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (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/CspLibPei.C 17    7/14/11 2:44p Artems $
//
// $Revision: 17 $
//
// $Date: 7/14/11 2:44p $
//
//*****************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/Chipset/Template/CSPLibrary/CspLibPei.C $
// 
// 17    7/14/11 2:44p Artems
// EIP 64106: Updated source to be UEFI 2.3.1 and PI 1.2 compliant
// 
// 16    3/23/11 1:02p Artems
// Bug fix - added backward compatibility with Core 4.6.4.1
// 
// 15    2/22/11 3:48p Artems
// EIP 51548 - Added AMI copyright headers, replaced TABs with spaces
// 
// 1     2/02/11 5:17p Artems
// 
// 14    5/07/10 10:09a Artems
// Fixed bug that causes build error when use Core 4.6.4.0
// 
// 13    5/06/10 12:22p Artems
// EIP 38241 - $FID signature is absent
// 
// 12    8/14/09 10:47a Robert
// Added FID.asm to the component for compliance with AMI Utility
// specification
// 
// 11    6/11/09 5:43p Robert
// Comment updates for CHM and coding standard
// 
// 10    10/13/07 11:49p Michaela
// added PciTableInit2 with a PCI access width parameter to support
// PCI initialization tables for various access widths
// 
// 9     2/16/07 6:13p Felixp
// Better handling of Firmware ID structure:
// 1. FW_VERSION_GUID and BIOS Tag come from SDL tokens.
// 2. Core/Project versions properly reported
// 3. CSM version removed
// 
// 5     6/06/05 3:20p Felixp
// updated to match PEI CIS 0.91 (CpuIo and PciCfg usage model changed)
// 
// 4     4/08/05 11:39a Sivagarn
// Included FID table
// 
// 3     2/15/05 12:29p Sivagarn
// Optimized the register programming call
// 
// 1     1/21/05 12:46p Sivagarn
// Initial Checkin - Version 0.05
//
//*****************************************************************************


//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:        CspLibPei.C
//
// Description: 
//  This file contains code for Generic CSP Library PEI functions.  The 
//  functions include PCI table update etc.
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>


//============================================================================
// Module specific Includes
#include <token.h>
#include <Efi.h>
#include <Pei.h>
#include <StatusCodes.h>
#include <AmiLib.h>
#include <AmiPeiLib.h>
#include <PPI\CspLibPpi.h>
#include <PPI\PCICfg.h>



//============================================================================
// GUID Definitions
EFI_GUID    gPeiPCITableInitPCIGUID = AMI_PEI_PCI_TABLE_INIT_PPI_GUID;

//============================================================================


#if CORE_REVISION <= 3
#include "ppi\FwVersion.h"
extern FW_VERSION   FwVersionData;
FW_VERSION *Version = &FwVersionData;
#endif    //#if CORE_REVISION <= 3

#ifndef PI_SPECIFICATION_VERSION //old Core

EFI_STATUS PciCfgModify(
    IN CONST EFI_PEI_SERVICES 	**PeiServices,
    IN EFI_PEI_PCI_CFG_PPI_WIDTH	Width,
    IN UINT64					Address,
    IN UINTN					SetBits,
    IN UINTN					ClearBits)
{
    if((*PeiServices)->PciCfg==NULL)
        return EFI_NOT_AVAILABLE_YET;

    return (*PeiServices)->PciCfg->Modify(
                    (EFI_PEI_SERVICES**)PeiServices,
                    (*PeiServices)->PciCfg,
                    Width, Address,
                    SetBits, ClearBits);
}
#endif


EFI_STATUS PciTableInit (
    IN EFI_PEI_SERVICES                **PeiServices,
    IN AMI_PEI_PCI_TABLE_INIT_PPI      *This,
    IN EFI_PEI_PCI_CFG2_PPI            *PciCfg,
    IN UINT64                          Address,
    IN AMI_PEI_PCI_INIT_TABLE_STRUCT   *PCIInitTable,
    IN UINT16                          wSize
);

EFI_STATUS PciTableInit2 (
    IN EFI_PEI_SERVICES                **PeiServices,
    IN AMI_PEI_PCI_TABLE_INIT_PPI      *This,
    IN EFI_PEI_PCI_CFG2_PPI            *PciCfg,        // OPTIONAL
    IN UINT64                          CfgAddress,
    IN AMI_PEI_PCI_INIT_TABLE_STRUCT2  *PciInitTable,
    IN UINT16                          TableEntries,
    IN EFI_PEI_PCI_CFG_PPI_WIDTH       AccessWidth
);


// PPI interface definition
AMI_PEI_PCI_TABLE_INIT_PPI  mPciTableInitPpi =
{
    PciTableInit,
    PciTableInit2,
};

static EFI_PEI_PPI_DESCRIPTOR mPpiList[] =  { 
    (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
    &gPeiPCITableInitPCIGUID,
    &mPciTableInitPpi};

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   PciTableInit
//
// Description: 
//  This function programs the PCI device with the values provided 
//  in the init table provided
//
// Input:
//  EFI_PEI_SERVICES **PeiServices - Pointer to the PEI Core data Structure
//  AMI_PEI_PCI_TABLE_INIT_PPI *This - Pointer to an instance of the AMI PEI PCI TABLE INIT PPI
//  EFI_PEI_PCI_CFG_PPI *PciCfg - Optional pointer to an instance of the PciCfg PPI
//  UINT64 Address - PCI address of the register to write to (Bus/Dev/Func/Reg)
//  AMI_PEI_PCI_INIT_TABLE_STRUCT *PCIInitTable - Table with register number, set and clear bits
//  UINT16 wSize - Table length (multiples of structure)
//
// Output:      
//  Always returns EFI_SUCCESS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS PciTableInit (
    IN EFI_PEI_SERVICES                **PeiServices,
    IN AMI_PEI_PCI_TABLE_INIT_PPI      *This,
    IN EFI_PEI_PCI_CFG2_PPI            *PciCfg,
    IN UINT64                          Address,
    IN AMI_PEI_PCI_INIT_TABLE_STRUCT   *PCIInitTable,
    IN UINT16                          wSize)
{
    EFI_STATUS      Status = EFI_SUCCESS;
    UINTN           Index;
    UINT64          LocalAddr;


    if ((! wSize) || (!PCIInitTable))
        return Status;

    // Take data defined in the PCIInitTable and program the PCI devices
    // as ported
    for (Index = 0; Index < wSize; Index ++) {
        LocalAddr = Address + PCIInitTable[Index].bRegIndex;

        PciCfgModify( PeiServices, 
                      EfiPeiPciCfgWidthUint8,
                      LocalAddr, 
                      PCIInitTable[Index].bORMask, 
                      ~PCIInitTable[Index].bANDMask );
    }

    return EFI_SUCCESS;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   PciTableInit2
//
// Description: 
//  This function is identical to PciTableInit with the addition of an extra 
//  parameter to specify PCI access width.
//
// Input:
//  EFI_PEI_SERVICES **PeiServices - Pointer to the PEI Core data Structure
//  AMI_PEI_PCI_TABLE_INIT_PPI *This - Pointer to an instance of the AMI PEI PCI TABLE INIT PPI
//  EFI_PEI_PCI_CFG_PPI *PciCfg - Optional pointer to an instance of the PciCfg PPI
//  UINT64 CfgAddress - PCI address of the register to write to (Bus/Dev/Func/Reg)
//  AMI_PEI_PCI_INIT_TABLE_STRUCT2 *PCIInitTable - Table with register number, set and clear bits
//  UINT16 TableEntries - Table length (multiples of structure)
//  EFI_PEI_PCI_CFG_PPI_WIDTH AccessWidth - Register-level access width
//
// Output:      
//  Always returns EFI_SUCCESS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS PciTableInit2 (
    IN EFI_PEI_SERVICES                **PeiServices,
    IN AMI_PEI_PCI_TABLE_INIT_PPI      *This,
    IN EFI_PEI_PCI_CFG2_PPI            *PciCfg,        // OPTIONAL
    IN UINT64                          CfgAddress,
    IN AMI_PEI_PCI_INIT_TABLE_STRUCT2  *PciInitTable,
    IN UINT16                          TableEntries,
    IN EFI_PEI_PCI_CFG_PPI_WIDTH       AccessWidth)
{
    EFI_STATUS      Status = EFI_SUCCESS;
    UINTN           Index;
    UINT64          LocalAddr;


    if ((! TableEntries) || (!PciInitTable))
        return Status;

    // Take data defined in the PCIInitTable and program the PCI devices
    // as ported
    for (Index = 0; 
         Index < TableEntries && !EFI_ERROR(Status); 
         Index ++) 
    {
        LocalAddr = CfgAddress + PciInitTable[Index].bRegIndex;

        Status = PciCfgModify( PeiServices,
                               AccessWidth,
                               LocalAddr,
                               PciInitTable[Index].bORMask,
                               PciInitTable[Index].bANDMask );
    }

    return EFI_SUCCESS;
}


//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   CspLibPei_Init
//
// Description: 
//  This function is the entry point for this PEI. This function initializes 
//  installs the CSP PPI
//
// Input:       
//  FfsHeader   Pointer to the FFS file header
//  PeiServices Pointer to the PEI services table
//
// Output:      
//  Return Status based on errors that are returned by the InstallPpi function
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS CspLibPei_Init (
    IN EFI_FFS_FILE_HEADER       *FfsHeader,
    IN EFI_PEI_SERVICES          **PeiServices)
{
    EFI_STATUS                  Status;

    // Install the NB Init Policy PPI
    Status = (*PeiServices)->InstallPpi(PeiServices, &mPpiList[0]);
#ifdef EFI_DEBUG
    if (Status) {
        PEI_TRACE((TRACE_PEI_CHIPSET, PeiServices, "CspLibPei_Init Return Code : %r\n", Status));
    }
#endif
    return Status;
}

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