330a02e3d0d1ada4549053b8a81e66889a7c4aff
[coreboot.git] / src / vendorcode / amd / agesa / f14 / Proc / GNB / PCIe / Family / 0x14 / F14PcieWrapperServices.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * Family specific PCIe wrapper configuration services
6  *
7  *
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:     AGESA
11  * @e sub-project: GNB
12  * @e \$Revision: 44325 $   @e \$Date: 2010-12-22 03:29:53 -0700 (Wed, 22 Dec 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 #include  "AGESA.h"
52 #include  "Ids.h"
53 #include  "Gnb.h"
54 #include  "GnbPcie.h"
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"
62 #include  "NbSmuLib.h"
63 #include  "Filecode.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  *----------------------------------------------------------------------------------------
68  */
69 extern BUILD_OPT_CFG UserOptions;
70
71 /*----------------------------------------------------------------------------------------
72  *                  T Y P E D E F S     A N D     S T R U C T U  R E S
73  *----------------------------------------------------------------------------------------
74  */
75
76
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  *----------------------------------------------------------------------------------------
80  */
81
82 AGESA_STATUS
83 STATIC
84 PcieOnConfigureGppEnginesLaneAllocation (
85   IN      PCIe_WRAPPER_CONFIG           *Wrapper,
86   IN      UINT8                         ConfigurationId
87   );
88
89 AGESA_STATUS
90 STATIC
91 PcieOnConfigureDdiEnginesLaneAllocation (
92   IN      PCIe_WRAPPER_CONFIG           *Wrapper,
93   IN      UINT8                         ConfigurationId
94   );
95
96 VOID
97 PcieFmExecuteNativeGen1Reconfig (
98   IN      PCIe_PLATFORM_CONFIG  *Pcie
99   );
100
101 AGESA_STATUS
102 PcieOnGetGppConfigurationValue (
103   IN       UINT64    ConfigurationSignature,
104      OUT   UINT8     *ConfigurationValue
105   );
106
107 /*----------------------------------------------------------------------------------------
108  *           T A B L E S
109  *----------------------------------------------------------------------------------------
110  */
111 PCIE_HOST_REGISTER_ENTRY PcieInitTable [] = {
112   {
113     PHY_SPACE (0, 0, D0F0xE4_PHY_6440_ADDRESS),
114     D0F0xE4_PHY_6440_RxInCalForce_MASK,
115     0x1 << D0F0xE4_PHY_6440_RxInCalForce_OFFSET
116   },
117   {
118     PHY_SPACE (0, 0, D0F0xE4_PHY_6480_ADDRESS),
119     D0F0xE4_PHY_6480_RxInCalForce_MASK,
120     0x1 << D0F0xE4_PHY_6480_RxInCalForce_OFFSET
121   },
122   {
123     PHY_SPACE (0, 0, D0F0xE4_PHY_6500_ADDRESS),
124     D0F0xE4_PHY_6500_RxInCalForce_MASK,
125     0x1 << D0F0xE4_PHY_6500_RxInCalForce_OFFSET
126   },
127   {
128     PHY_SPACE (0, 0, D0F0xE4_PHY_6600_ADDRESS),
129     D0F0xE4_PHY_6600_RxInCalForce_MASK,
130     0x1 << D0F0xE4_PHY_6600_RxInCalForce_OFFSET
131   },
132   {
133     PHY_SPACE (0, 0, D0F0xE4_PHY_6840_ADDRESS),
134     D0F0xE4_PHY_6840_RxInCalForce_MASK,
135     0x1 << D0F0xE4_PHY_6840_RxInCalForce_OFFSET
136   },
137   {
138     PHY_SPACE (0, 0, D0F0xE4_PHY_6880_ADDRESS),
139     D0F0xE4_PHY_6880_RxInCalForce_MASK,
140     0x1 << D0F0xE4_PHY_6880_RxInCalForce_OFFSET
141   },
142   {
143     PHY_SPACE (0, 0, D0F0xE4_PHY_6900_ADDRESS),
144     D0F0xE4_PHY_6900_RxInCalForce_MASK,
145     0x1 << D0F0xE4_PHY_6900_RxInCalForce_OFFSET
146   },
147   {
148     PHY_SPACE (0, 0, D0F0xE4_PHY_6A00_ADDRESS),
149     D0F0xE4_PHY_6A00_RxInCalForce_MASK,
150     0x1 << D0F0xE4_PHY_6A00_RxInCalForce_OFFSET
151   },
152   {
153     WRAP_SPACE (0, D0F0xE4_WRAP_8016_ADDRESS),
154     D0F0xE4_WRAP_8016_CalibAckLatency_MASK,
155     0
156   },
157   {
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)
161   },
162   {
163     D0F0xE4_x0108_8071_ADDRESS,
164     D0F0xE4_x0108_8071_RxAdjust_MASK,
165     0x3 << D0F0xE4_x0108_8071_RxAdjust_OFFSET
166   },
167   {
168     D0F0xE4_x0108_8072_ADDRESS,
169     D0F0xE4_x0108_8072_TxAdjust_MASK,
170     0x3 << D0F0xE4_x0108_8072_TxAdjust_OFFSET
171   },
172 };
173
174 /*----------------------------------------------------------------------------------------*/
175 /**
176  * Configure engine list to support lane allocation according to configuration ID.
177  *
178  *
179  *
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
186  */
187 AGESA_STATUS
188 PcieFmConfigureEnginesLaneAllocation (
189   IN      PCIe_WRAPPER_CONFIG           *Wrapper,
190   IN      PCIE_ENGINE_TYPE              EngineType,
191   IN      UINT8                         ConfigurationId
192   )
193 {
194   AGESA_STATUS  Status;
195   Status = AGESA_ERROR;
196   switch (Wrapper->WrapId) {
197   case GPP_WRAP_ID:
198     if (EngineType != PciePortEngine) {
199       return AGESA_UNSUPPORTED;
200     }
201     Status = PcieOnConfigureGppEnginesLaneAllocation (Wrapper, ConfigurationId);
202     break;
203   case DDI_WRAP_ID:
204     if (EngineType != PcieDdiEngine) {
205       return AGESA_UNSUPPORTED;
206     }
207     Status = PcieOnConfigureDdiEnginesLaneAllocation (Wrapper, ConfigurationId);
208     break;
209   default:
210     ASSERT (FALSE);
211
212   }
213   return Status;
214 }
215
216 CONST UINT8 GppLaneConfigurationTable [][NUMBER_OF_GPP_PORTS * 2] = {
217 //4     5                                6                               7                                8 (SB)
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}
224 };
225
226 CONST UINT8 GppPortIdConfigurationTable [][NUMBER_OF_GPP_PORTS] = {
227 //4  5  6  7  8 (SB)
228   {1, 2, 3, 4, 0},
229   {1, 2, 3, 4, 0},
230   {1, 3, 2, 4, 0},
231   {1, 2, 3, 4, 0},
232   {1, 4, 2, 3, 0},
233   {1, 2, 3, 4, 0}
234 };
235
236 /*----------------------------------------------------------------------------------------*/
237 /**
238  * Configure GFX engine list to support lane allocation according to configuration ID.
239  *
240  *
241  *
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
246  */
247
248
249 AGESA_STATUS
250 STATIC
251 PcieOnConfigureGppEnginesLaneAllocation (
252   IN      PCIe_WRAPPER_CONFIG           *Wrapper,
253   IN      UINT8                         ConfigurationId
254   )
255 {
256   PCIe_ENGINE_CONFIG  *EnginesList;
257   UINTN               CoreLaneIndex;
258   UINTN               PortIdIndex;
259   if (ConfigurationId > ((sizeof (GppLaneConfigurationTable) / (NUMBER_OF_GPP_PORTS * 2)) - 1)) {
260     return AGESA_ERROR;
261   }
262   EnginesList = PcieWrapperGetEngineList (Wrapper);
263   CoreLaneIndex = 0;
264   PortIdIndex = 0;
265   do {
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++];
270
271   } while (IS_LAST_DESCRIPTOR (EnginesList++));
272   return  AGESA_SUCCESS;
273 }
274
275
276 CONST UINT8 DdiLaneConfigurationTable [][NUMBER_OF_DDIS * 2] = {
277   {0,  3,   4,   7,  8,  11}
278 };
279
280 /*----------------------------------------------------------------------------------------*/
281 /**
282  * Configure DDI engine list to support lane allocation according to configuration ID.
283  *
284  *
285  *
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
290  */
291
292
293 AGESA_STATUS
294 STATIC
295 PcieOnConfigureDdiEnginesLaneAllocation (
296   IN      PCIe_WRAPPER_CONFIG           *Wrapper,
297   IN      UINT8                         ConfigurationId
298   )
299 {
300   PCIe_ENGINE_CONFIG  *EnginesList;
301   UINTN               LaneIndex;
302   EnginesList = PcieWrapperGetEngineList (Wrapper);
303   if (ConfigurationId > ((sizeof (DdiLaneConfigurationTable) / (NUMBER_OF_DDIS * 2)) - 1)) {
304     return AGESA_ERROR;
305   }
306   LaneIndex = 0;
307   do {
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;
315 }
316
317 /*----------------------------------------------------------------------------------------*/
318 /**
319  * Configure clock to run out of the wrapper at specific speed
320  *
321  *
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
325  */
326 VOID
327 PcieFmConfigureClock (
328   IN      PCIE_LINK_SPEED_CAP           LinkSpeedCapability,
329   IN      PCIe_WRAPPER_CONFIG           *Wrapper,
330   IN      PCIe_PLATFORM_CONFIG          *Pcie
331   )
332 {
333 }
334
335
336 /*----------------------------------------------------------------------------------------*/
337 /**
338  * Get configuration Value for GPP wrapper
339  *
340  *
341  *
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
346  */
347 AGESA_STATUS
348 PcieOnGetGppConfigurationValue (
349   IN       UINT64    ConfigurationSignature,
350      OUT   UINT8     *ConfigurationValue
351   )
352 {
353   switch (ConfigurationSignature) {
354   case GPP_CORE_x4x1x1x1x1:
355     *ConfigurationValue = 0x4;
356     break;
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;
362     break;
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;
368     break;
369   case GPP_CORE_x4x4:
370     *ConfigurationValue = 0x1;
371     break;
372   default:
373     ASSERT (FALSE);
374     return  AGESA_ERROR;
375   }
376   return  AGESA_SUCCESS;
377 }
378
379 /*----------------------------------------------------------------------------------------*/
380 /**
381  * Get core configuration value
382  *
383  *
384  *
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
391  */
392 AGESA_STATUS
393 PcieFmGetCoreConfigurationValue (
394   IN      PCIe_WRAPPER_CONFIG   *Wrapper,
395   IN      UINT8                 CoreId,
396   IN      UINT64                ConfigurationSignature,
397   IN      UINT8                 *ConfigurationValue
398   )
399 {
400   AGESA_STATUS  Status;
401
402   if (Wrapper->WrapId == GPP_WRAP_ID) {
403     Status = PcieOnGetGppConfigurationValue (ConfigurationSignature, ConfigurationValue);
404   } else {
405     Status = AGESA_ERROR;
406   }
407   return  Status;
408 }
409
410 /*----------------------------------------------------------------------------------------*/
411 /**
412  * Get max link speed capability supported by this port
413  *
414  *
415  *
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
420  */
421 PCIE_LINK_SPEED_CAP
422 PcieFmGetLinkSpeedCap (
423   IN       UINT32                Flags,
424   IN       PCIe_ENGINE_CONFIG    *Engine,
425   IN       PCIe_PLATFORM_CONFIG  *Pcie
426   )
427 {
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;
433   }
434   if (Pcie->PsppPolicy == PsppPowerSaving) {
435     LinkSpeedCapability = PcieGen1;
436   }
437   if (Engine->Type.Port.PortData.LinkSpeedCapability < LinkSpeedCapability) {
438     LinkSpeedCapability = Engine->Type.Port.PortData.LinkSpeedCapability;
439   }
440   if ((Flags & PCIE_PORT_GEN_CAP_BOOT) != 0) {
441     if (Pcie->PsppPolicy == PsppBalanceLow || Engine->Type.Port.PortData.MiscControls.LinkSafeMode == PcieGen1) {
442       LinkSpeedCapability = PcieGen1;
443     }
444   }
445   return LinkSpeedCapability;
446 }
447
448
449 /*----------------------------------------------------------------------------------------*/
450 /**
451  * Various initialization  needed prior topology and configuration initialization
452  *
453  *
454  *
455  * @param[in]  Pcie            Pointer to global PCIe configuration
456  *
457  */
458 VOID
459 PcieFmPreInit (
460   IN       PCIe_PLATFORM_CONFIG  *Pcie
461   )
462 {
463   UINT32                    Index;
464   PCIe_SILICON_CONFIG       *Silicon;
465   PCIE_LINK_SPEED_CAP       GlobalCapability;
466   F14_PCIe_WRAPPER_CONFIG   *F14PcieWrapper;
467
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,
472                        Pcie
473                        );
474   if ((GlobalCapability == PcieGen1)  && (F14PcieWrapper->NativeGen1Support == TRUE)) {
475     PcieFmExecuteNativeGen1Reconfig (Pcie);
476   }
477   Silicon = PcieComplexGetSiliconList (&Pcie->ComplexList[0]);
478   for (Index = 0; Index < (sizeof (PcieInitTable) / sizeof (PCIE_HOST_REGISTER_ENTRY)); Index++) {
479     PcieSiliconRegisterRMW (
480       Silicon,
481       PcieInitTable[Index].Reg,
482       PcieInitTable[Index].Mask,
483       PcieInitTable[Index].Data,
484       FALSE,
485       Pcie
486       );
487   }
488
489   // Set PCIe SSID.
490   PcieSiliconRegisterRMW (
491     Silicon,
492     WRAP_SPACE (0, D0F0xE4_WRAP_8002_ADDRESS),
493     D0F0xE4_WRAP_8002_SubsystemVendorID_MASK | D0F0xE4_WRAP_8002_SubsystemID_MASK,
494     UserOptions.CfgGnbPcieSSID,
495     FALSE,
496     Pcie
497     );
498 }
499
500 /*----------------------------------------------------------------------------------------*/
501 /**
502  * Check if engine can be remapped to Device/function number requested by user
503  * defined engine descriptor
504  *
505  *   Function only called if requested device/function does not much native device/function
506  *
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
511  */
512
513 BOOLEAN
514 PcieFmCheckPortPciDeviceMapping (
515   IN      PCIe_PORT_DESCRIPTOR  *PortDescriptor,
516   IN      PCIe_ENGINE_CONFIG    *Engine
517   )
518 {
519   return FALSE;
520 }
521
522 /*----------------------------------------------------------------------------------------*/
523 /**
524  * Get core configuration string
525  *
526  *   Debug function for logging configuration
527  *
528  * @param[in] Wrapper              Pointer to internal configuration data area
529  * @param[in] ConfigurationValue   Configuration value
530  * @retval                         Configuration string
531  */
532
533 CONST CHAR8*
534 PcieFmDebugGetCoreConfigurationString (
535   IN      PCIe_WRAPPER_CONFIG   *Wrapper,
536   IN      UINT8                 ConfigurationValue
537   )
538 {
539   switch (ConfigurationValue) {
540   case 4:
541     return (CONST CHAR8*)"1x4, 4x1";
542   case 3:
543     return (CONST CHAR8*)"1x4, 1x2, 2x1";
544   case 2:
545     return (CONST CHAR8*)"1x4, 2x2";
546   case 1:
547     return (CONST CHAR8*)"1x4, 1x4";
548   default:
549     break;
550   }
551   return (CONST CHAR8*)" !!! Something Wrong !!!";
552 }
553
554 /*----------------------------------------------------------------------------------------*/
555 /**
556  * Get wrapper name
557  *
558  *  Debug function for logging wrapper name
559  *
560  * @param[in] Wrapper              Pointer to internal configuration data area
561  * @retval                         Wrapper Name string
562  */
563
564 CONST CHAR8*
565 PcieFmDebugGetWrapperNameString (
566   IN      PCIe_WRAPPER_CONFIG   *Wrapper
567   )
568 {
569   switch (Wrapper->WrapId) {
570   case  GPP_WRAP_ID:
571     return (CONST CHAR8*)"GPPSB";
572   case  DDI_WRAP_ID:
573     return (CONST CHAR8*)"Virtual DDI";
574   default:
575     break;
576   }
577   return (CONST CHAR8*)" !!! Something Wrong !!!";
578 }
579
580 /*----------------------------------------------------------------------------------------*/
581 /**
582  * Get register address name
583  *
584  *  Debug function for logging register trace
585  *
586  * @param[in] AddressFrame         Address Frame
587  * @retval                         Register address name
588  */
589 CONST CHAR8*
590 PcieFmDebugGetHostRegAddressSpaceString (
591   IN      UINT16                 AddressFrame
592   )
593 {
594   switch (AddressFrame) {
595   case  0x130:
596     return (CONST CHAR8*)"GPP WRAP";
597   case  0x110:
598     return (CONST CHAR8*)"GPP PIF0";
599   case  0x120:
600     return (CONST CHAR8*)"GPP PHY0";
601   case  0x101:
602     return (CONST CHAR8*)"GPP CORE";
603   default:
604     break;
605   }
606   return (CONST CHAR8*)" !!! Something Wrong !!!";
607 }
608
609
610 /*----------------------------------------------------------------------------------------*/
611 /**
612  * Execute/clean up reconfiguration for Gen 1 native mode
613  *
614  *
615  *
616  * @param[in]  Pcie                Pointer to global PCIe configuration
617  */
618 VOID
619 PcieFmExecuteNativeGen1Reconfig (
620   IN      PCIe_PLATFORM_CONFIG  *Pcie
621   )
622 {
623   IDS_HDT_CONSOLE (GNB_TRACE, "PcieFmExecuteNativeGen1Reconfig Enter\n");
624   NbSmuServiceRequest (19, FALSE, GnbLibGetHeader (Pcie));
625   IDS_HDT_CONSOLE (GNB_TRACE, "PcieFmExecuteNativeGen1Reconfig Enter\n");
626 }
627
628 /*----------------------------------------------------------------------------------------*/
629 /**
630  * Check if the lane can be muxed by link width requested by user
631  * defined engine descriptor
632  *
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.
635  *
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
640  */
641
642 BOOLEAN
643 PcieFmCheckPortPcieLaneCanBeMuxed (
644   IN      PCIe_PORT_DESCRIPTOR  *PortDescriptor,
645   IN      PCIe_ENGINE_CONFIG    *Engine
646   )
647 {
648   UINT16  DescriptorHiLane;
649   UINT16  DescriptorLoLane;
650   UINT16  DescriptorNumberOfLanes;
651   PCIe_WRAPPER_CONFIG         *Wrapper;
652   UINT16                      NormalizedLoPhyLane;
653   BOOLEAN                     Result;
654
655   Result  = FALSE;
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;
660
661   NormalizedLoPhyLane = DescriptorLoLane - Wrapper->StartPhyLane;
662
663   if (NormalizedLoPhyLane == Engine->Type.Port.StartCoreLane) {
664     Result = TRUE;
665   } else {
666     if (((Engine->Type.Port.StartCoreLane % 2) == 0) || (Engine->Type.Port.StartCoreLane == 0)) {
667       if (NormalizedLoPhyLane == 0) {
668         Result = TRUE;
669       } else {
670         if (((NormalizedLoPhyLane % 2) == 0) && ((NormalizedLoPhyLane % DescriptorNumberOfLanes) == 0)) {
671           Result = TRUE;
672         }
673       }
674     }
675   }
676
677   return Result;
678 }