blob: f2187410ccb33c06328e1c720ea230dafbefe0d9 [file] [log] [blame]
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001/* $NoKeywords:$ */
2/**
3 * @file
4 *
5 * PCIe utility. Various supporting functions.
6 *
7 *
8 *
9 * @xrefitem bom "File Content Label" "Release Content"
10 * @e project: AGESA
11 * @e sub-project: GNB
12 * @e \$Revision: 38931 $ @e \$Date: 2010-10-01 15:50:05 -0700 (Fri, 01 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#include "AGESA.h"
52#include "Ids.h"
53#include "Gnb.h"
54#include "GnbPcie.h"
55#include "GnbPcieFamServices.h"
56#include GNB_MODULE_DEFINITIONS (GnbCommonLib)
57#include GNB_MODULE_DEFINITIONS (GnbPcieInitLibV1)
58#include GNB_MODULE_DEFINITIONS (GnbPcieConfig)
efdesign9884cbce22011-08-04 12:09:17 -060059#include "PcieMiscLib.h"
Frank Vibrans2b4c8312011-02-14 18:30:54 +000060#include "GnbRegistersON.h"
61#include "Filecode.h"
62#define FILECODE PROC_GNB_PCIE_PCIEMISCLIB_FILECODE
63/*----------------------------------------------------------------------------------------
64 * D E F I N I T I O N S A N D M A C R O S
65 *----------------------------------------------------------------------------------------
66 */
67
68
69/*----------------------------------------------------------------------------------------
70 * T Y P E D E F S A N D S T R U C T U R E S
71 *----------------------------------------------------------------------------------------
72 */
73typedef struct {
74 UINT32 Flags;
75 PCIE_LINK_SPEED_CAP LinkSpeedCapability;
76} PCIE_GLOBAL_GEN_CAP_WORKSPACE;
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 * Training state handling
87 *
88 *
89 *
90 * @param[in] Engine Pointer to engine config descriptor
91 * @param[in, out] Buffer Indicate if engine in non final state
92 * @param[in] Pcie Pointer to global PCIe configuration
93 *
94 */
95
96VOID
97STATIC
98PcieUtilGlobalGenCapabilityCallback (
99 IN PCIe_ENGINE_CONFIG *Engine,
100 IN OUT VOID *Buffer,
101 IN PCIe_PLATFORM_CONFIG *Pcie
102 )
103{
104 PCIE_GLOBAL_GEN_CAP_WORKSPACE *GlobalGenCapability;
105 PCIE_LINK_SPEED_CAP LinkSpeedCapability;
106 PCIE_HOTPLUG_TYPE HotPlugType;
107 UINT32 Flags;
108
109 Flags = PCIE_GLOBAL_GEN_CAP_ALL_PORTS;
110 GlobalGenCapability = (PCIE_GLOBAL_GEN_CAP_WORKSPACE*) Buffer;
111 LinkSpeedCapability = PcieGen1;
112 if (PcieConfigCheckPortStatus (Engine, INIT_STATUS_PCIE_TRAINING_SUCCESS)) {
113 Flags |= PCIE_GLOBAL_GEN_CAP_TRAINED_PORTS;
114 }
115 HotPlugType = Engine->Type.Port.PortData.LinkHotplug;
116 if ((HotPlugType == HotplugBasic) || (HotPlugType == HotplugServer) || (HotPlugType == HotplugEnhanced)) {
117 Flags |= PCIE_GLOBAL_GEN_CAP_HOTPLUG_PORTS;
118 }
119 if ((GlobalGenCapability->Flags & Flags) != 0) {
120 ASSERT ((GlobalGenCapability->Flags & (PCIE_PORT_GEN_CAP_MAX | PCIE_PORT_GEN_CAP_BOOT)) != 0);
121 LinkSpeedCapability = PcieFmGetLinkSpeedCap (GlobalGenCapability->Flags, Engine, Pcie);
122 if (GlobalGenCapability->LinkSpeedCapability < LinkSpeedCapability) {
123 GlobalGenCapability->LinkSpeedCapability = LinkSpeedCapability;
124 }
125 }
126}
127
128/*----------------------------------------------------------------------------------------*/
129/**
130 * Determine global GEN capability
131 *
132 *
133 * @param[in] Flags global GEN capability flags
134 * @param[in] Pcie Pointer to global PCIe configuration
135 *
136 */
137PCIE_LINK_SPEED_CAP
138PcieUtilGlobalGenCapability (
139 IN UINT32 Flags,
140 IN PCIe_PLATFORM_CONFIG *Pcie
141 )
142{
143 PCIE_LINK_SPEED_CAP GlobalCapability;
144 PCIE_GLOBAL_GEN_CAP_WORKSPACE GlobalGenCap;
145
146 GlobalGenCap.LinkSpeedCapability = PcieGen1;
147 GlobalGenCap.Flags = Flags;
148 PcieConfigRunProcForAllEngines (
149 DESCRIPTOR_ALLOCATED | DESCRIPTOR_PCIE_ENGINE,
150 PcieUtilGlobalGenCapabilityCallback,
151 &GlobalGenCap,
152 Pcie
153 );
154
155 GlobalCapability = GlobalGenCap.LinkSpeedCapability;
156
157 return GlobalCapability;
158}
159