5 * Family specific PCIe wrapper configuration services
9 * @xrefitem bom "File Content Label" "Release Content"
12 * @e \$Revision: 44325 $ @e \$Date: 2010-12-22 03:29:53 -0700 (Wed, 22 Dec 2010) $
16 *****************************************************************************
18 * Copyright (c) 2011, Advanced Micro Devices, Inc.
19 * All rights reserved.
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.
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.
43 * ***************************************************************************
47 /*----------------------------------------------------------------------------------------
48 * M O D U L E S U S E D
49 *----------------------------------------------------------------------------------------
55 #include "PcieFamilyServices.h"
56 #include GNB_MODULE_DEFINITIONS (GnbCommonLib)
57 #include GNB_MODULE_DEFINITIONS (GnbPcieInitLibV1)
58 #include "PcieMiscLib.h"
59 #include "GnbPcieFamServices.h"
60 #include "OntarioDefinitions.h"
61 #include "GnbRegistersON.h"
64 #define FILECODE PROC_GNB_PCIE_FAMILY_0X14_F14PCIEWRAPPERSERVICES_FILECODE
65 /*----------------------------------------------------------------------------------------
66 * D E F I N I T I O N S A N D M A C R O S
67 *----------------------------------------------------------------------------------------
69 extern BUILD_OPT_CFG UserOptions;
71 /*----------------------------------------------------------------------------------------
72 * T Y P E D E F S A N D S T R U C T U R E S
73 *----------------------------------------------------------------------------------------
77 /*----------------------------------------------------------------------------------------
78 * 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
79 *----------------------------------------------------------------------------------------
84 PcieOnConfigureGppEnginesLaneAllocation (
85 IN PCIe_WRAPPER_CONFIG *Wrapper,
86 IN UINT8 ConfigurationId
91 PcieOnConfigureDdiEnginesLaneAllocation (
92 IN PCIe_WRAPPER_CONFIG *Wrapper,
93 IN UINT8 ConfigurationId
97 PcieFmExecuteNativeGen1Reconfig (
98 IN PCIe_PLATFORM_CONFIG *Pcie
102 PcieOnGetGppConfigurationValue (
103 IN UINT64 ConfigurationSignature,
104 OUT UINT8 *ConfigurationValue
107 /*----------------------------------------------------------------------------------------
109 *----------------------------------------------------------------------------------------
111 PCIE_HOST_REGISTER_ENTRY PcieInitTable [] = {
113 PHY_SPACE (0, 0, D0F0xE4_PHY_6440_ADDRESS),
114 D0F0xE4_PHY_6440_RxInCalForce_MASK,
115 0x1 << D0F0xE4_PHY_6440_RxInCalForce_OFFSET
118 PHY_SPACE (0, 0, D0F0xE4_PHY_6480_ADDRESS),
119 D0F0xE4_PHY_6480_RxInCalForce_MASK,
120 0x1 << D0F0xE4_PHY_6480_RxInCalForce_OFFSET
123 PHY_SPACE (0, 0, D0F0xE4_PHY_6500_ADDRESS),
124 D0F0xE4_PHY_6500_RxInCalForce_MASK,
125 0x1 << D0F0xE4_PHY_6500_RxInCalForce_OFFSET
128 PHY_SPACE (0, 0, D0F0xE4_PHY_6600_ADDRESS),
129 D0F0xE4_PHY_6600_RxInCalForce_MASK,
130 0x1 << D0F0xE4_PHY_6600_RxInCalForce_OFFSET
133 PHY_SPACE (0, 0, D0F0xE4_PHY_6840_ADDRESS),
134 D0F0xE4_PHY_6840_RxInCalForce_MASK,
135 0x1 << D0F0xE4_PHY_6840_RxInCalForce_OFFSET
138 PHY_SPACE (0, 0, D0F0xE4_PHY_6880_ADDRESS),
139 D0F0xE4_PHY_6880_RxInCalForce_MASK,
140 0x1 << D0F0xE4_PHY_6880_RxInCalForce_OFFSET
143 PHY_SPACE (0, 0, D0F0xE4_PHY_6900_ADDRESS),
144 D0F0xE4_PHY_6900_RxInCalForce_MASK,
145 0x1 << D0F0xE4_PHY_6900_RxInCalForce_OFFSET
148 PHY_SPACE (0, 0, D0F0xE4_PHY_6A00_ADDRESS),
149 D0F0xE4_PHY_6A00_RxInCalForce_MASK,
150 0x1 << D0F0xE4_PHY_6A00_RxInCalForce_OFFSET
153 WRAP_SPACE (0, D0F0xE4_WRAP_8016_ADDRESS),
154 D0F0xE4_WRAP_8016_CalibAckLatency_MASK,
158 PHY_SPACE (0, 0, D0F0xE4_PHY_4004_ADDRESS),
159 D0F0xE4_PHY_4004_PllBiasGenPdnbOvrdVal_MASK | D0F0xE4_PHY_4004_PllBiasGenPdnbOvrdEn_MASK,
160 (0x1 << D0F0xE4_PHY_4004_PllBiasGenPdnbOvrdVal_OFFSET) | (0x1 << D0F0xE4_PHY_4004_PllBiasGenPdnbOvrdEn_OFFSET)
163 D0F0xE4_x0108_8071_ADDRESS,
164 D0F0xE4_x0108_8071_RxAdjust_MASK,
165 0x3 << D0F0xE4_x0108_8071_RxAdjust_OFFSET
168 D0F0xE4_x0108_8072_ADDRESS,
169 D0F0xE4_x0108_8072_TxAdjust_MASK,
170 0x3 << D0F0xE4_x0108_8072_TxAdjust_OFFSET
174 /*----------------------------------------------------------------------------------------*/
176 * Configure engine list to support lane allocation according to configuration ID.
180 * @param[in] Wrapper Pointer to wrapper config descriptor
181 * @param[in] EngineType Engine Type
182 * @param[in] ConfigurationId Configuration ID
183 * @retval AGESA_SUCCESS Configuration successfully applied
184 * @retval AGESA_UNSUPPORTED No more configuration available for given engine type
185 * @retval AGESA_ERROR Requested configuration not supported
188 PcieFmConfigureEnginesLaneAllocation (
189 IN PCIe_WRAPPER_CONFIG *Wrapper,
190 IN PCIE_ENGINE_TYPE EngineType,
191 IN UINT8 ConfigurationId
195 Status = AGESA_ERROR;
196 switch (Wrapper->WrapId) {
198 if (EngineType != PciePortEngine) {
199 return AGESA_UNSUPPORTED;
201 Status = PcieOnConfigureGppEnginesLaneAllocation (Wrapper, ConfigurationId);
204 if (EngineType != PcieDdiEngine) {
205 return AGESA_UNSUPPORTED;
207 Status = PcieOnConfigureDdiEnginesLaneAllocation (Wrapper, ConfigurationId);
216 CONST UINT8 GppLaneConfigurationTable [][NUMBER_OF_GPP_PORTS * 2] = {
218 {4, 7, UNUSED_LANE_ID, UNUSED_LANE_ID, UNUSED_LANE_ID, UNUSED_LANE_ID, UNUSED_LANE_ID, UNUSED_LANE_ID, 0, 3},
219 {4, 5, 6, 7, UNUSED_LANE_ID, UNUSED_LANE_ID, UNUSED_LANE_ID, UNUSED_LANE_ID, 0, 3},
220 {4, 5, UNUSED_LANE_ID, UNUSED_LANE_ID, 6, 7, UNUSED_LANE_ID, UNUSED_LANE_ID, 0, 3},
221 {4, 5, 6, 6, 7, 7, UNUSED_LANE_ID, UNUSED_LANE_ID, 0, 3},
222 {4, 5, UNUSED_LANE_ID, UNUSED_LANE_ID, 6, 6, 7, 7, 0, 3},
223 {4, 4, 5, 5, 6, 6, 7, 7, 0, 3}
226 CONST UINT8 GppPortIdConfigurationTable [][NUMBER_OF_GPP_PORTS] = {
236 /*----------------------------------------------------------------------------------------*/
238 * Configure GFX engine list to support lane allocation according to configuration ID.
242 * @param[in] Wrapper Pointer to wrapper config descriptor
243 * @param[in] ConfigurationId Configuration ID
244 * @retval AGESA_SUCCESS Configuration successfully applied
245 * @retval AGESA_ERROR Requested configuration not supported
251 PcieOnConfigureGppEnginesLaneAllocation (
252 IN PCIe_WRAPPER_CONFIG *Wrapper,
253 IN UINT8 ConfigurationId
256 PCIe_ENGINE_CONFIG *EnginesList;
259 if (ConfigurationId > ((sizeof (GppLaneConfigurationTable) / (NUMBER_OF_GPP_PORTS * 2)) - 1)) {
262 EnginesList = PcieWrapperGetEngineList (Wrapper);
266 EnginesList->Flags &= ~DESCRIPTOR_ALLOCATED;
267 EnginesList->Type.Port.PortId = GppPortIdConfigurationTable [ConfigurationId][PortIdIndex++];
268 EnginesList->Type.Port.StartCoreLane = GppLaneConfigurationTable [ConfigurationId][CoreLaneIndex++];
269 EnginesList->Type.Port.EndCoreLane = GppLaneConfigurationTable [ConfigurationId][CoreLaneIndex++];
271 } while (IS_LAST_DESCRIPTOR (EnginesList++));
272 return AGESA_SUCCESS;
276 CONST UINT8 DdiLaneConfigurationTable [][NUMBER_OF_DDIS * 2] = {
280 /*----------------------------------------------------------------------------------------*/
282 * Configure DDI engine list to support lane allocation according to configuration ID.
286 * @param[in] Wrapper Pointer to wrapper config descriptor
287 * @param[in] ConfigurationId Configuration ID
288 * @retval AGESA_SUCCESS Configuration successfully applied
289 * @retval AGESA_ERROR Requested configuration not supported
295 PcieOnConfigureDdiEnginesLaneAllocation (
296 IN PCIe_WRAPPER_CONFIG *Wrapper,
297 IN UINT8 ConfigurationId
300 PCIe_ENGINE_CONFIG *EnginesList;
302 EnginesList = PcieWrapperGetEngineList (Wrapper);
303 if (ConfigurationId > ((sizeof (DdiLaneConfigurationTable) / (NUMBER_OF_DDIS * 2)) - 1)) {
308 EnginesList->Flags &= ~DESCRIPTOR_ALLOCATED;
309 EnginesList->EngineData.StartLane = DdiLaneConfigurationTable [ConfigurationId][LaneIndex++] +
310 Wrapper->StartPhyLane;
311 EnginesList->EngineData.EndLane = DdiLaneConfigurationTable [ConfigurationId][LaneIndex++] +
312 Wrapper->StartPhyLane;
313 } while (IS_LAST_DESCRIPTOR (EnginesList++));
314 return AGESA_SUCCESS;
317 /*----------------------------------------------------------------------------------------*/
319 * Configure clock to run out of the wrapper at specific speed
322 * @param[in] LinkSpeedCapability Link Speed capability
323 * @param[in] Wrapper Pointer to wrapper config descriptor
324 * @param[in] Pcie Pointer to global PCIe configuration
327 PcieFmConfigureClock (
328 IN PCIE_LINK_SPEED_CAP LinkSpeedCapability,
329 IN PCIe_WRAPPER_CONFIG *Wrapper,
330 IN PCIe_PLATFORM_CONFIG *Pcie
336 /*----------------------------------------------------------------------------------------*/
338 * Get configuration Value for GPP wrapper
342 * @param[in] ConfigurationSignature Configuration signature
343 * @param[out] ConfigurationValue Configuration value
344 * @retval AGESA_SUCCESS Correct core configuration value returned by in *ConfigurationValue
345 * @retval AGESA_ERROR ConfigurationSignature is incorrect
348 PcieOnGetGppConfigurationValue (
349 IN UINT64 ConfigurationSignature,
350 OUT UINT8 *ConfigurationValue
353 switch (ConfigurationSignature) {
354 case GPP_CORE_x4x1x1x1x1:
355 *ConfigurationValue = 0x4;
357 case GPP_CORE_x4x2x1x1:
358 case GPP_CORE_x4x2x1x1_ST:
359 //Configuration 2:1:1 - Device Numbers 4:5:6
360 //Configuration 2:1:1 - Device Numbers 4:6:7
361 *ConfigurationValue = 0x3;
363 case GPP_CORE_x4x2x2:
364 case GPP_CORE_x4x2x2_ST:
365 //Configuration 2:2 - Device Numbers 4:5
366 //Configuration 2:2 - Device Numbers 4:6
367 *ConfigurationValue = 0x2;
370 *ConfigurationValue = 0x1;
376 return AGESA_SUCCESS;
379 /*----------------------------------------------------------------------------------------*/
381 * Get core configuration value
385 * @param[in] Wrapper Pointer to internal configuration data area
386 * @param[in] CoreId Core ID
387 * @param[in] ConfigurationSignature Configuration signature
388 * @param[out] ConfigurationValue Configuration value (for core configuration)
389 * @retval AGESA_SUCCESS Configuration successfully applied
390 * @retval AGESA_ERROR Core configuration value can not be determined
393 PcieFmGetCoreConfigurationValue (
394 IN PCIe_WRAPPER_CONFIG *Wrapper,
396 IN UINT64 ConfigurationSignature,
397 IN UINT8 *ConfigurationValue
402 if (Wrapper->WrapId == GPP_WRAP_ID) {
403 Status = PcieOnGetGppConfigurationValue (ConfigurationSignature, ConfigurationValue);
405 Status = AGESA_ERROR;
410 /*----------------------------------------------------------------------------------------*/
412 * Get max link speed capability supported by this port
416 * @param[in] Flags See Flags PCIE_PORT_GEN_CAP_BOOT / PCIE_PORT_GEN_CAP_MAX
417 * @param[in] Engine Pointer to engine config descriptor
418 * @param[in] Pcie Pointer to global PCIe configuration
419 * @retval PcieGen1/PcieGen2 Max supported link gen capability
422 PcieFmGetLinkSpeedCap (
424 IN PCIe_ENGINE_CONFIG *Engine,
425 IN PCIe_PLATFORM_CONFIG *Pcie
428 PCIE_LINK_SPEED_CAP LinkSpeedCapability;
429 ASSERT (Engine->Type.Port.PortData.LinkSpeedCapability < MaxPcieGen);
430 LinkSpeedCapability = PcieGen2;
431 if (Engine->Type.Port.PortData.LinkSpeedCapability == PcieGenMaxSupported) {
432 Engine->Type.Port.PortData.LinkSpeedCapability = (UINT8) LinkSpeedCapability;
434 if (Pcie->PsppPolicy == PsppPowerSaving) {
435 LinkSpeedCapability = PcieGen1;
437 if (Engine->Type.Port.PortData.LinkSpeedCapability < LinkSpeedCapability) {
438 LinkSpeedCapability = Engine->Type.Port.PortData.LinkSpeedCapability;
440 if ((Flags & PCIE_PORT_GEN_CAP_BOOT) != 0) {
441 if (Pcie->PsppPolicy == PsppBalanceLow || Engine->Type.Port.PortData.MiscControls.LinkSafeMode == PcieGen1) {
442 LinkSpeedCapability = PcieGen1;
445 return LinkSpeedCapability;
449 /*----------------------------------------------------------------------------------------*/
451 * Various initialization needed prior topology and configuration initialization
455 * @param[in] Pcie Pointer to global PCIe configuration
460 IN PCIe_PLATFORM_CONFIG *Pcie
464 PCIe_SILICON_CONFIG *Silicon;
465 PCIE_LINK_SPEED_CAP GlobalCapability;
466 F14_PCIe_WRAPPER_CONFIG *F14PcieWrapper;
468 Silicon = PcieComplexGetSiliconList (&Pcie->ComplexList[0]);
469 F14PcieWrapper = &((F14_COMPLEX_CONFIG*) Silicon)->FmGppWrapper ;
470 GlobalCapability = PcieUtilGlobalGenCapability (
471 PCIE_PORT_GEN_CAP_MAX | PCIE_GLOBAL_GEN_CAP_ALL_PORTS,
474 if ((GlobalCapability == PcieGen1) && (F14PcieWrapper->NativeGen1Support == TRUE)) {
475 PcieFmExecuteNativeGen1Reconfig (Pcie);
477 Silicon = PcieComplexGetSiliconList (&Pcie->ComplexList[0]);
478 for (Index = 0; Index < (sizeof (PcieInitTable) / sizeof (PCIE_HOST_REGISTER_ENTRY)); Index++) {
479 PcieSiliconRegisterRMW (
481 PcieInitTable[Index].Reg,
482 PcieInitTable[Index].Mask,
483 PcieInitTable[Index].Data,
490 PcieSiliconRegisterRMW (
492 WRAP_SPACE (0, D0F0xE4_WRAP_8002_ADDRESS),
493 D0F0xE4_WRAP_8002_SubsystemVendorID_MASK | D0F0xE4_WRAP_8002_SubsystemID_MASK,
494 UserOptions.CfgGnbPcieSSID,
500 /*----------------------------------------------------------------------------------------*/
502 * Check if engine can be remapped to Device/function number requested by user
503 * defined engine descriptor
505 * Function only called if requested device/function does not much native device/function
507 * @param[in] PortDescriptor Pointer to user defined engine descriptor
508 * @param[in] Engine Pointer engine configuration
509 * @retval TRUE Descriptor can be mapped to engine
510 * @retval FALSE Descriptor can NOT be mapped to engine
514 PcieFmCheckPortPciDeviceMapping (
515 IN PCIe_PORT_DESCRIPTOR *PortDescriptor,
516 IN PCIe_ENGINE_CONFIG *Engine
522 /*----------------------------------------------------------------------------------------*/
524 * Get core configuration string
526 * Debug function for logging configuration
528 * @param[in] Wrapper Pointer to internal configuration data area
529 * @param[in] ConfigurationValue Configuration value
530 * @retval Configuration string
534 PcieFmDebugGetCoreConfigurationString (
535 IN PCIe_WRAPPER_CONFIG *Wrapper,
536 IN UINT8 ConfigurationValue
539 switch (ConfigurationValue) {
541 return (CONST CHAR8*)"1x4, 4x1";
543 return (CONST CHAR8*)"1x4, 1x2, 2x1";
545 return (CONST CHAR8*)"1x4, 2x2";
547 return (CONST CHAR8*)"1x4, 1x4";
551 return (CONST CHAR8*)" !!! Something Wrong !!!";
554 /*----------------------------------------------------------------------------------------*/
558 * Debug function for logging wrapper name
560 * @param[in] Wrapper Pointer to internal configuration data area
561 * @retval Wrapper Name string
565 PcieFmDebugGetWrapperNameString (
566 IN PCIe_WRAPPER_CONFIG *Wrapper
569 switch (Wrapper->WrapId) {
571 return (CONST CHAR8*)"GPPSB";
573 return (CONST CHAR8*)"Virtual DDI";
577 return (CONST CHAR8*)" !!! Something Wrong !!!";
580 /*----------------------------------------------------------------------------------------*/
582 * Get register address name
584 * Debug function for logging register trace
586 * @param[in] AddressFrame Address Frame
587 * @retval Register address name
590 PcieFmDebugGetHostRegAddressSpaceString (
591 IN UINT16 AddressFrame
594 switch (AddressFrame) {
596 return (CONST CHAR8*)"GPP WRAP";
598 return (CONST CHAR8*)"GPP PIF0";
600 return (CONST CHAR8*)"GPP PHY0";
602 return (CONST CHAR8*)"GPP CORE";
606 return (CONST CHAR8*)" !!! Something Wrong !!!";
610 /*----------------------------------------------------------------------------------------*/
612 * Execute/clean up reconfiguration for Gen 1 native mode
616 * @param[in] Pcie Pointer to global PCIe configuration
619 PcieFmExecuteNativeGen1Reconfig (
620 IN PCIe_PLATFORM_CONFIG *Pcie
623 IDS_HDT_CONSOLE (GNB_TRACE, "PcieFmExecuteNativeGen1Reconfig Enter\n");
624 NbSmuServiceRequest (19, FALSE, GnbLibGetHeader (Pcie));
625 IDS_HDT_CONSOLE (GNB_TRACE, "PcieFmExecuteNativeGen1Reconfig Enter\n");
628 /*----------------------------------------------------------------------------------------*/
630 * Check if the lane can be muxed by link width requested by user
631 * defined engine descriptor
633 * Check Engine StartCoreLane could be aligned by user requested link width(x1, x2, x4, x8, x16).
634 * Check Engine StartCoreLane could be aligned by user requested link width x2.
636 * @param[in] PortDescriptor Pointer to user defined engine descriptor
637 * @param[in] Engine Pointer engine configuration
638 * @retval TRUE Lane can be muxed
639 * @retval FALSE LAne can NOT be muxed
643 PcieFmCheckPortPcieLaneCanBeMuxed (
644 IN PCIe_PORT_DESCRIPTOR *PortDescriptor,
645 IN PCIe_ENGINE_CONFIG *Engine
648 UINT16 DescriptorHiLane;
649 UINT16 DescriptorLoLane;
650 UINT16 DescriptorNumberOfLanes;
651 PCIe_WRAPPER_CONFIG *Wrapper;
652 UINT16 NormalizedLoPhyLane;
656 Wrapper = (PCIe_WRAPPER_CONFIG *)Engine->Wrapper;
657 DescriptorLoLane = MIN (PortDescriptor->EngineData.StartLane, PortDescriptor->EngineData.EndLane);
658 DescriptorHiLane = MAX (PortDescriptor->EngineData.StartLane, PortDescriptor->EngineData.EndLane);
659 DescriptorNumberOfLanes = DescriptorHiLane - DescriptorLoLane + 1;
661 NormalizedLoPhyLane = DescriptorLoLane - Wrapper->StartPhyLane;
663 if (NormalizedLoPhyLane == Engine->Type.Port.StartCoreLane) {
666 if (((Engine->Type.Port.StartCoreLane % 2) == 0) || (Engine->Type.Port.StartCoreLane == 0)) {
667 if (NormalizedLoPhyLane == 0) {
670 if (((NormalizedLoPhyLane % 2) == 0) && ((NormalizedLoPhyLane % DescriptorNumberOfLanes) == 0)) {