blob: 8b49ad8973bdbf1b7a1d0d228ced8f316c9c324b [file] [log] [blame]
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001/* $NoKeywords:$ */
2/**
3 * @file
4 *
5 * Pre-training PCIe subsystem initialization routines.
6 *
7 *
8 *
9 * @xrefitem bom "File Content Label" "Release Content"
10 * @e project: AGESA
11 * @e sub-project: GNB
12 * @e \$Revision: 39275 $ @e \$Date: 2010-10-09 08:22:05 +0800 (Sat, 09 Oct 2010) $
13 *
14 */
15/*
16 *****************************************************************************
17 *
18 * Copyright (c) 2011, Advanced Micro Devices, Inc.
19 * All rights reserved.
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions are met:
23 * * Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * * Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
29 * its contributors may be used to endorse or promote products derived
30 * from this software without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
36 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 * ***************************************************************************
44 *
45 */
46
47/*----------------------------------------------------------------------------------------
48 * M O D U L E S U S E D
49 *----------------------------------------------------------------------------------------
50 */
51
52#include "AGESA.h"
53#include "Ids.h"
54#include "Gnb.h"
55#include "GnbPcie.h"
56#include "GnbPcieFamServices.h"
57#include "PcieFamilyServices.h"
58#include "PcieInit.h"
59#include "PcieMiscLib.h"
60#include GNB_MODULE_DEFINITIONS (GnbPcieInitLibV1)
61#include GNB_MODULE_DEFINITIONS (GnbPcieConfig)
62#include GNB_MODULE_DEFINITIONS (GnbPcieTrainingV1)
63#include "GnbRegistersON.h"
64#include "Filecode.h"
65#define FILECODE PROC_GNB_PCIE_PCIEINIT_FILECODE
66/*----------------------------------------------------------------------------------------
67 * D E F I N I T I O N S A N D M A C R O S
68 *----------------------------------------------------------------------------------------
69 */
70
71
72/*----------------------------------------------------------------------------------------
73 * T Y P E D E F S A N D S T R U C T U R E S
74 *----------------------------------------------------------------------------------------
75 */
76
77
78/*----------------------------------------------------------------------------------------
79 * P R O T O T Y P E S O F L O C A L F U N C T I O N S
80 *----------------------------------------------------------------------------------------
81 */
82
83
84/*----------------------------------------------------------------------------------------*/
85/**
86 * Control port visibility in PCI config space
87 *
88 *
89 * @param[in] Control Make port Hide/Unhide ports
90 * @param[in] Pcie Pointer to global PCIe configuration
91 */
92VOID
93PciePortsVisibilityControl (
94 IN PCIE_PORT_VISIBILITY Control,
95 IN PCIe_PLATFORM_CONFIG *Pcie
96 )
97{
98 PCIe_COMPLEX_CONFIG *ComplexList;
99 ComplexList = &Pcie->ComplexList[0];
100 while (ComplexList != NULL) {
101 PCIe_SILICON_CONFIG *SiliconList;
102 SiliconList = PcieComplexGetSiliconList (ComplexList);
103 while (SiliconList != NULL) {
104 PcieFmPortVisabilityControl (Control, SiliconList, Pcie);
105 SiliconList = PcieLibGetNextDescriptor (SiliconList);
106 }
107 ComplexList = PcieLibGetNextDescriptor (ComplexList);
108 }
109}
110
111
112PCIE_HOST_REGISTER_ENTRY CoreInitTable [] = {
113 {
114 D0F0xE4_CORE_0020_ADDRESS,
Frank.Vibrans9c2fb602011-03-17 22:19:45 +0000115 D0F0xE4_CORE_0020_CiRcOrderingDis_MASK,
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000116 (0x1 << D0F0xE4_CORE_0020_CiRcOrderingDis_OFFSET)
117 },
118 {
Frank.Vibrans9c2fb602011-03-17 22:19:45 +0000119 0x10,
120 0x1c00,
121 (0x4 << 10)
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000122 },
123 {
124 D0F0xE4_CORE_001C_ADDRESS,
125 D0F0xE4_CORE_001C_TxArbRoundRobinEn_MASK |
126 D0F0xE4_CORE_001C_TxArbSlvLimit_MASK |
127 D0F0xE4_CORE_001C_TxArbMstLimit_MASK,
128 (0x1 << D0F0xE4_CORE_001C_TxArbRoundRobinEn_OFFSET) |
129 (0x4 << D0F0xE4_CORE_001C_TxArbSlvLimit_OFFSET) |
130 (0x4 << D0F0xE4_CORE_001C_TxArbMstLimit_OFFSET)
131 },
132 {
133 D0F0xE4_CORE_0040_ADDRESS,
134 D0F0xE4_CORE_0040_PElecIdleMode_MASK,
135 (0x2 << D0F0xE4_CORE_0040_PElecIdleMode_OFFSET)
136 },
137 {
138 D0F0xE4_CORE_0002_ADDRESS,
139 D0F0xE4_CORE_0002_HwDebug_0__MASK,
140 (0x1 << D0F0xE4_CORE_0002_HwDebug_0__OFFSET)
141 },
142 {
143 D0F0xE4_CORE_00C1_ADDRESS,
144 D0F0xE4_CORE_00C1_StrapLinkBwNotificationCapEn_MASK |
145 D0F0xE4_CORE_00C1_StrapGen2Compliance_MASK,
146 (0x1 << D0F0xE4_CORE_00C1_StrapLinkBwNotificationCapEn_OFFSET) |
147 (0x1 << D0F0xE4_CORE_00C1_StrapGen2Compliance_OFFSET)
148 },
149 {
150 D0F0xE4_CORE_00B0_ADDRESS,
Frank.Vibrans9c2fb602011-03-17 22:19:45 +0000151 D0F0xE4_CORE_00B0_StrapF0MsiEn_MASK,
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000152 (0x1 << D0F0xE4_CORE_00B0_StrapF0MsiEn_OFFSET)
153 }
154};
155
156/*----------------------------------------------------------------------------------------*/
157/**
158 * Common Core Init
159 *
160 *
161 * @param[in] Wrapper Pointer to wrapper configuration descriptor
162 * @param[in] Pcie Pointer to global PCIe configuration
163 */
164VOID
165PcieCommonCoreInit (
166 IN PCIe_WRAPPER_CONFIG *Wrapper,
167 IN PCIe_PLATFORM_CONFIG *Pcie
168 )
169{
170 UINT8 CoreId;
171 UINTN Index;
172 if (PcieLibIsPcieWrapper (Wrapper)) {
173 IDS_HDT_CONSOLE (GNB_TRACE, "PcieCommonCoreInit Enter\n");
174 for (CoreId = Wrapper->StartPcieCoreId; CoreId <= Wrapper->EndPcieCoreId; CoreId++) {
175 for (Index = 0; Index < sizeof (CoreInitTable) / sizeof (PCIE_HOST_REGISTER_ENTRY); Index++) {
176 UINT32 Value;
177 Value = PcieRegisterRead (
178 Wrapper,
179 CORE_SPACE (CoreId, CoreInitTable[Index].Reg),
180 Pcie
181 );
182 Value &= (~CoreInitTable[Index].Mask);
183 Value |= CoreInitTable[Index].Data;
184 PcieRegisterWrite (
185 Wrapper,
186 CORE_SPACE (CoreId, CoreInitTable[Index].Reg),
187 Value,
188 FALSE,
189 Pcie
190 );
191 }
192 }
193 IDS_HDT_CONSOLE (GNB_TRACE, "PcieCommonCoreInit Exit\n");
194 }
195}
196
197
198/*----------------------------------------------------------------------------------------*/
199/**
200 * Per wrapper Pcie Init SRBM reset prior Aaccess to wrapper registers.
201 *
202 *
203 * @param[in] Wrapper Pointer to wrapper configuration descriptor
204 * @param[in] Buffer Pointer buffer
205 * @param[in] Pcie Pointer to global PCIe configuration
206 */
207AGESA_STATUS
208PcieInitSrbmCallback (
209 IN PCIe_WRAPPER_CONFIG *Wrapper,
210 IN OUT VOID *Buffer,
211 IN PCIe_PLATFORM_CONFIG *Pcie
212 )
213{
214 PcieTopologyInitSrbmReset (TRUE, Wrapper, Pcie);
215 return AGESA_SUCCESS;
216}
217/*----------------------------------------------------------------------------------------*/
218/**
219 * Per wrapper Pcie Init prior training.
220 *
221 *
222 * @param[in] Wrapper Pointer to wrapper configuration descriptor
223 * @param[in] Buffer Pointer buffer
224 * @param[in] Pcie Pointer to global PCIe configuration
225 */
226AGESA_STATUS
227PcieInitCallback (
228 IN PCIe_WRAPPER_CONFIG *Wrapper,
229 IN OUT VOID *Buffer,
230 IN PCIe_PLATFORM_CONFIG *Pcie
231 )
232{
233 AGESA_STATUS Status;
234 PcieTopologyPrepareForReconfig (Wrapper, Pcie);
235 Status = PcieTopologySetCoreConfig (Wrapper, Pcie);
236 ASSERT (Status == AGESA_SUCCESS);
237 PcieTopologyApplyLaneMux (Wrapper, Pcie);
238 PcieFmPifSetRxDetectPowerMode (Wrapper, Pcie);
239 PciePifSetLs2ExitTime (Wrapper, Pcie);
240 PcieTopologySelectMasterPll (Wrapper, Pcie);
241 PcieTopologyExecuteReconfig (Wrapper, Pcie);
242 PcieTopologySetLinkReversal (Wrapper, Pcie);
243 PciePifApplyGanging (Wrapper, Pcie);
244 PcieFmPhyApplyGanging (Wrapper, Pcie);
245 PciePifPllInitForDdi (Wrapper, Pcie);
246 PcieTopologyLaneControl (
247 DisableLanes,
248 PcieUtilGetWrapperLaneBitMap (LANE_TYPE_ALL, LANE_TYPE_PCIE_ALLOCATED, Wrapper, Pcie),
249 Wrapper,
250 Pcie
251 );
252 PcieSetDdiOwnPhy (Wrapper, Pcie);
253 PciePollPifForCompeletion (Wrapper, Pcie);
254 PcieFmAvertClockPickers (Wrapper, Pcie);
255 PcieFmConfigureClock (PcieGen1, Wrapper, Pcie);
256 PcieCommonCoreInit (Wrapper, Pcie);
257 PciePifDisableFifoReset (Wrapper, Pcie);
258 return Status;
259}
260
261/*----------------------------------------------------------------------------------------*/
262/**
263 * Pcie Init
264 *
265 *
266 *
267 * @param[in] Pcie Pointer to global PCIe configuration
268 * @retval AGESA_SUCCESS Topology successfully mapped
269 * @retval AGESA_ERROR Topology can not be mapped
270 */
271
272AGESA_STATUS
273PcieInit (
274 IN PCIe_PLATFORM_CONFIG *Pcie
275 )
276{
277 AGESA_STATUS Status;
278 AGESA_STATUS AgesaStatus;
279 IDS_HDT_CONSOLE (GNB_TRACE, "PcieInit Enter\n");
280 AgesaStatus = AGESA_SUCCESS;
281 Status = PcieConfigRunProcForAllWrappers (DESCRIPTOR_ALL_WRAPPERS, PcieInitSrbmCallback, NULL, Pcie);
282 AGESA_STATUS_UPDATE (Status, AgesaStatus);
283 PcieFmPreInit (Pcie);
284 Status = PcieConfigRunProcForAllWrappers (DESCRIPTOR_ALL_WRAPPERS, PcieInitCallback, NULL, Pcie);
285 AGESA_STATUS_UPDATE (Status, AgesaStatus);
286 PcieFmSetBootUpVoltage (PcieGen1, Pcie);
287 IDS_HDT_CONSOLE (GNB_TRACE, "PcieInit Exit [%x]\n", AgesaStatus);
288 return AgesaStatus;
289}
290
291
292/*----------------------------------------------------------------------------------------*/
293/**
294 * Per wrapper Pcie Init prior training.
295 *
296 *
297 * @param[in] Wrapper Pointer to wrapper configuration descriptor
298 * @param[in] Buffer Pointer buffer
299 * @param[in] Pcie Pointer to global PCIe configuration
300 */
301AGESA_STATUS
302PciePostInitCallback (
303 IN PCIe_WRAPPER_CONFIG *Wrapper,
304 IN OUT VOID *Buffer,
305 IN PCIe_PLATFORM_CONFIG *Pcie
306 )
307{
308 AGESA_STATUS Status;
309
310 Status = AGESA_SUCCESS;
311 PcieFmConfigureClock (
312 PcieUtilGlobalGenCapability (PCIE_PORT_GEN_CAP_BOOT | PCIE_GLOBAL_GEN_CAP_ALL_PORTS, Pcie),
313 Wrapper,
314 Pcie
315 );
316 return Status;
317}
318
319/*----------------------------------------------------------------------------------------*/
320/**
321 * Pcie Init
322 *
323 *
324 *
325 * @param[in] Pcie Pointer to global PCIe configuration
326 * @retval AGESA_SUCCESS Topology successfully mapped
327 * @retval AGESA_ERROR Topology can not be mapped
328 */
329
330AGESA_STATUS
331PciePostInit (
332 IN PCIe_PLATFORM_CONFIG *Pcie
333 )
334{
335 AGESA_STATUS Status;
336 AGESA_STATUS AgesaStatus;
337
338 IDS_HDT_CONSOLE (GNB_TRACE, "PciePostInit Enter\n");
339 AgesaStatus = AGESA_SUCCESS;
340 Status = PcieConfigRunProcForAllWrappers (DESCRIPTOR_PCIE_WRAPPER, PciePostInitCallback, NULL, Pcie);
341 AGESA_STATUS_UPDATE (Status, AgesaStatus);
342 PcieFmSetBootUpVoltage (
343 PcieUtilGlobalGenCapability (PCIE_PORT_GEN_CAP_BOOT | PCIE_GLOBAL_GEN_CAP_ALL_PORTS, Pcie),
344 Pcie
345 );
346 IDS_HDT_CONSOLE (GNB_TRACE, "PciePostInit Exit [%x]\n", AgesaStatus);
347 return AgesaStatus;
348}
349