blob: 318bb8256615563394121768925589d30fa19dd7 [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.
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +100020 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000021 * 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.
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +100028 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
29 * its contributors may be used to endorse or promote products derived
Frank Vibrans2b4c8312011-02-14 18:30:54 +000030 * from this software without specific prior written permission.
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +100031 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000032 * 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.
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +100042 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000043 * ***************************************************************************
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
efdesign9884cbce22011-08-04 12:09:17 -060083VOID
84PcieCommonCoreInit (
85 IN PCIe_WRAPPER_CONFIG *Wrapper,
86 IN PCIe_PLATFORM_CONFIG *Pcie
87 );
88
89AGESA_STATUS
90PcieInitSrbmCallback (
91 IN PCIe_WRAPPER_CONFIG *Wrapper,
92 IN OUT VOID *Buffer,
93 IN PCIe_PLATFORM_CONFIG *Pcie
94 );
95
96AGESA_STATUS
97PcieInitCallback (
98 IN PCIe_WRAPPER_CONFIG *Wrapper,
99 IN OUT VOID *Buffer,
100 IN PCIe_PLATFORM_CONFIG *Pcie
101 );
102
103AGESA_STATUS
104PciePostInitCallback (
105 IN PCIe_WRAPPER_CONFIG *Wrapper,
106 IN OUT VOID *Buffer,
107 IN PCIe_PLATFORM_CONFIG *Pcie
108 );
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000109
110/*----------------------------------------------------------------------------------------*/
111/**
112 * Control port visibility in PCI config space
113 *
114 *
115 * @param[in] Control Make port Hide/Unhide ports
116 * @param[in] Pcie Pointer to global PCIe configuration
117 */
118VOID
119PciePortsVisibilityControl (
120 IN PCIE_PORT_VISIBILITY Control,
121 IN PCIe_PLATFORM_CONFIG *Pcie
122 )
123{
124 PCIe_COMPLEX_CONFIG *ComplexList;
125 ComplexList = &Pcie->ComplexList[0];
126 while (ComplexList != NULL) {
127 PCIe_SILICON_CONFIG *SiliconList;
128 SiliconList = PcieComplexGetSiliconList (ComplexList);
129 while (SiliconList != NULL) {
130 PcieFmPortVisabilityControl (Control, SiliconList, Pcie);
131 SiliconList = PcieLibGetNextDescriptor (SiliconList);
132 }
133 ComplexList = PcieLibGetNextDescriptor (ComplexList);
134 }
135}
136
137
138PCIE_HOST_REGISTER_ENTRY CoreInitTable [] = {
139 {
140 D0F0xE4_CORE_0020_ADDRESS,
Frank.Vibrans9c2fb602011-03-17 22:19:45 +0000141 D0F0xE4_CORE_0020_CiRcOrderingDis_MASK,
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000142 (0x1 << D0F0xE4_CORE_0020_CiRcOrderingDis_OFFSET)
143 },
144 {
Frank.Vibrans9c2fb602011-03-17 22:19:45 +0000145 0x10,
146 0x1c00,
147 (0x4 << 10)
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000148 },
149 {
150 D0F0xE4_CORE_001C_ADDRESS,
151 D0F0xE4_CORE_001C_TxArbRoundRobinEn_MASK |
152 D0F0xE4_CORE_001C_TxArbSlvLimit_MASK |
153 D0F0xE4_CORE_001C_TxArbMstLimit_MASK,
154 (0x1 << D0F0xE4_CORE_001C_TxArbRoundRobinEn_OFFSET) |
155 (0x4 << D0F0xE4_CORE_001C_TxArbSlvLimit_OFFSET) |
156 (0x4 << D0F0xE4_CORE_001C_TxArbMstLimit_OFFSET)
157 },
158 {
159 D0F0xE4_CORE_0040_ADDRESS,
160 D0F0xE4_CORE_0040_PElecIdleMode_MASK,
161 (0x2 << D0F0xE4_CORE_0040_PElecIdleMode_OFFSET)
162 },
163 {
164 D0F0xE4_CORE_0002_ADDRESS,
165 D0F0xE4_CORE_0002_HwDebug_0__MASK,
166 (0x1 << D0F0xE4_CORE_0002_HwDebug_0__OFFSET)
167 },
168 {
169 D0F0xE4_CORE_00C1_ADDRESS,
170 D0F0xE4_CORE_00C1_StrapLinkBwNotificationCapEn_MASK |
171 D0F0xE4_CORE_00C1_StrapGen2Compliance_MASK,
172 (0x1 << D0F0xE4_CORE_00C1_StrapLinkBwNotificationCapEn_OFFSET) |
173 (0x1 << D0F0xE4_CORE_00C1_StrapGen2Compliance_OFFSET)
174 },
175 {
176 D0F0xE4_CORE_00B0_ADDRESS,
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +1000177 D0F0xE4_CORE_00B0_StrapF0MsiEn_MASK,
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000178 (0x1 << D0F0xE4_CORE_00B0_StrapF0MsiEn_OFFSET)
179 }
180};
181
182/*----------------------------------------------------------------------------------------*/
183/**
184 * Common Core Init
185 *
186 *
187 * @param[in] Wrapper Pointer to wrapper configuration descriptor
188 * @param[in] Pcie Pointer to global PCIe configuration
189 */
190VOID
191PcieCommonCoreInit (
192 IN PCIe_WRAPPER_CONFIG *Wrapper,
193 IN PCIe_PLATFORM_CONFIG *Pcie
194 )
195{
196 UINT8 CoreId;
197 UINTN Index;
198 if (PcieLibIsPcieWrapper (Wrapper)) {
199 IDS_HDT_CONSOLE (GNB_TRACE, "PcieCommonCoreInit Enter\n");
200 for (CoreId = Wrapper->StartPcieCoreId; CoreId <= Wrapper->EndPcieCoreId; CoreId++) {
Patrick Georgi6b688f52021-02-12 13:49:11 +0100201 for (Index = 0; Index < ARRAY_SIZE(CoreInitTable); Index++) {
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000202 UINT32 Value;
203 Value = PcieRegisterRead (
204 Wrapper,
205 CORE_SPACE (CoreId, CoreInitTable[Index].Reg),
206 Pcie
207 );
208 Value &= (~CoreInitTable[Index].Mask);
209 Value |= CoreInitTable[Index].Data;
210 PcieRegisterWrite (
211 Wrapper,
212 CORE_SPACE (CoreId, CoreInitTable[Index].Reg),
213 Value,
214 FALSE,
215 Pcie
216 );
217 }
218 }
219 IDS_HDT_CONSOLE (GNB_TRACE, "PcieCommonCoreInit Exit\n");
220 }
221}
222
223
224/*----------------------------------------------------------------------------------------*/
225/**
226 * Per wrapper Pcie Init SRBM reset prior Aaccess to wrapper registers.
227 *
228 *
229 * @param[in] Wrapper Pointer to wrapper configuration descriptor
230 * @param[in] Buffer Pointer buffer
231 * @param[in] Pcie Pointer to global PCIe configuration
232 */
233AGESA_STATUS
234PcieInitSrbmCallback (
235 IN PCIe_WRAPPER_CONFIG *Wrapper,
236 IN OUT VOID *Buffer,
237 IN PCIe_PLATFORM_CONFIG *Pcie
238 )
239{
240 PcieTopologyInitSrbmReset (TRUE, Wrapper, Pcie);
241 return AGESA_SUCCESS;
242}
243/*----------------------------------------------------------------------------------------*/
244/**
245 * Per wrapper Pcie Init prior training.
246 *
247 *
248 * @param[in] Wrapper Pointer to wrapper configuration descriptor
249 * @param[in] Buffer Pointer buffer
250 * @param[in] Pcie Pointer to global PCIe configuration
251 */
252AGESA_STATUS
253PcieInitCallback (
254 IN PCIe_WRAPPER_CONFIG *Wrapper,
255 IN OUT VOID *Buffer,
256 IN PCIe_PLATFORM_CONFIG *Pcie
257 )
258{
259 AGESA_STATUS Status;
260 PcieTopologyPrepareForReconfig (Wrapper, Pcie);
261 Status = PcieTopologySetCoreConfig (Wrapper, Pcie);
262 ASSERT (Status == AGESA_SUCCESS);
263 PcieTopologyApplyLaneMux (Wrapper, Pcie);
264 PcieFmPifSetRxDetectPowerMode (Wrapper, Pcie);
265 PciePifSetLs2ExitTime (Wrapper, Pcie);
266 PcieTopologySelectMasterPll (Wrapper, Pcie);
267 PcieTopologyExecuteReconfig (Wrapper, Pcie);
268 PcieTopologySetLinkReversal (Wrapper, Pcie);
269 PciePifApplyGanging (Wrapper, Pcie);
270 PcieFmPhyApplyGanging (Wrapper, Pcie);
271 PciePifPllInitForDdi (Wrapper, Pcie);
272 PcieTopologyLaneControl (
273 DisableLanes,
274 PcieUtilGetWrapperLaneBitMap (LANE_TYPE_ALL, LANE_TYPE_PCIE_ALLOCATED, Wrapper, Pcie),
275 Wrapper,
276 Pcie
277 );
278 PcieSetDdiOwnPhy (Wrapper, Pcie);
279 PciePollPifForCompeletion (Wrapper, Pcie);
280 PcieFmAvertClockPickers (Wrapper, Pcie);
281 PcieFmConfigureClock (PcieGen1, Wrapper, Pcie);
282 PcieCommonCoreInit (Wrapper, Pcie);
283 PciePifDisableFifoReset (Wrapper, Pcie);
284 return Status;
285}
286
287/*----------------------------------------------------------------------------------------*/
288/**
289 * Pcie Init
290 *
291 *
292 *
293 * @param[in] Pcie Pointer to global PCIe configuration
294 * @retval AGESA_SUCCESS Topology successfully mapped
295 * @retval AGESA_ERROR Topology can not be mapped
296 */
297
298AGESA_STATUS
299PcieInit (
300 IN PCIe_PLATFORM_CONFIG *Pcie
301 )
302{
303 AGESA_STATUS Status;
304 AGESA_STATUS AgesaStatus;
305 IDS_HDT_CONSOLE (GNB_TRACE, "PcieInit Enter\n");
306 AgesaStatus = AGESA_SUCCESS;
307 Status = PcieConfigRunProcForAllWrappers (DESCRIPTOR_ALL_WRAPPERS, PcieInitSrbmCallback, NULL, Pcie);
308 AGESA_STATUS_UPDATE (Status, AgesaStatus);
309 PcieFmPreInit (Pcie);
310 Status = PcieConfigRunProcForAllWrappers (DESCRIPTOR_ALL_WRAPPERS, PcieInitCallback, NULL, Pcie);
311 AGESA_STATUS_UPDATE (Status, AgesaStatus);
312 PcieFmSetBootUpVoltage (PcieGen1, Pcie);
313 IDS_HDT_CONSOLE (GNB_TRACE, "PcieInit Exit [%x]\n", AgesaStatus);
314 return AgesaStatus;
315}
316
317
318/*----------------------------------------------------------------------------------------*/
319/**
320 * Per wrapper Pcie Init prior training.
321 *
322 *
323 * @param[in] Wrapper Pointer to wrapper configuration descriptor
324 * @param[in] Buffer Pointer buffer
325 * @param[in] Pcie Pointer to global PCIe configuration
326 */
327AGESA_STATUS
328PciePostInitCallback (
329 IN PCIe_WRAPPER_CONFIG *Wrapper,
330 IN OUT VOID *Buffer,
331 IN PCIe_PLATFORM_CONFIG *Pcie
332 )
333{
334 AGESA_STATUS Status;
335
336 Status = AGESA_SUCCESS;
337 PcieFmConfigureClock (
338 PcieUtilGlobalGenCapability (PCIE_PORT_GEN_CAP_BOOT | PCIE_GLOBAL_GEN_CAP_ALL_PORTS, Pcie),
339 Wrapper,
340 Pcie
341 );
342 return Status;
343}
344
345/*----------------------------------------------------------------------------------------*/
346/**
347 * Pcie Init
348 *
349 *
350 *
351 * @param[in] Pcie Pointer to global PCIe configuration
352 * @retval AGESA_SUCCESS Topology successfully mapped
353 * @retval AGESA_ERROR Topology can not be mapped
354 */
355
356AGESA_STATUS
357PciePostInit (
358 IN PCIe_PLATFORM_CONFIG *Pcie
359 )
360{
361 AGESA_STATUS Status;
362 AGESA_STATUS AgesaStatus;
363
364 IDS_HDT_CONSOLE (GNB_TRACE, "PciePostInit Enter\n");
365 AgesaStatus = AGESA_SUCCESS;
366 Status = PcieConfigRunProcForAllWrappers (DESCRIPTOR_PCIE_WRAPPER, PciePostInitCallback, NULL, Pcie);
367 AGESA_STATUS_UPDATE (Status, AgesaStatus);
368 PcieFmSetBootUpVoltage (
369 PcieUtilGlobalGenCapability (PCIE_PORT_GEN_CAP_BOOT | PCIE_GLOBAL_GEN_CAP_ALL_PORTS, Pcie),
370 Pcie
371 );
372 IDS_HDT_CONSOLE (GNB_TRACE, "PciePostInit Exit [%x]\n", AgesaStatus);
373 return AgesaStatus;
374}
375