5 * Link optimization support.
7 * @xrefitem bom "File Content Label" "Release Content"
9 * @e sub-project: HyperTransport
10 * @e \$Revision: 56279 $ @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
14 *****************************************************************************
16 * Copyright (C) 2012 Advanced Micro Devices, Inc.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions are met:
21 * * Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * * Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
27 * its contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
34 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 * ***************************************************************************
46 *----------------------------------------------------------------------------
49 *----------------------------------------------------------------------------
60 #include "htInterface.h"
61 #include "htInterfaceGeneral.h"
64 #include "htNbCommonHardware.h"
65 #include "htNbOptimization.h"
70 #define FILECODE PROC_HT_NBCOMMON_HTNBOPTIMIZATION_FILECODE
71 /*----------------------------------------------------------------------------
72 * DEFINITIONS AND MACROS
74 *----------------------------------------------------------------------------
77 /***************************************************************************
78 *** Link Optimization ***
79 ***************************************************************************/
81 /*----------------------------------------------------------------------------------------*/
83 * Get Link features into system data structure.
85 * @HtNbMethod{::F_GATHER_LINK_FEATURES}
87 * For a specific discovered CPU Link, populate the port list with the frequency
88 * capabilities. Support for other link oriented capabilities, currently:
89 * - Unit ID Clumping. Set to disabled. This doesn't mean the CPU doesn't support clumping,
91 * - The CPU doesn't clump its host unit ids, and
92 * - We don't have to check as carefully in SetLinkData whether the port is an IO host link.
94 * @param[in,out] ThisPort The PortList structure entry for this link's port
95 * @param[in] Interface Access to non-HT support functions.
96 * @param[in] PlatformConfig Platform profile/build option config structure.
97 * @param[in] Nb this northbridge
101 IN OUT PORT_DESCRIPTOR *ThisPort,
102 IN HT_INTERFACE *Interface,
103 IN PLATFORM_CONFIGURATION *PlatformConfig,
109 UINT32 ExtendedFrequency;
111 Reg = ThisPort->Pointer;
112 Reg.Address.Register += HTHOST_FREQ_REV_REG;
113 LibAmdPciReadBits (Reg, 30, 16, &Frequency, Nb->ConfigHandle);
114 Reg = ThisPort->Pointer;
115 Reg.Address.Register += HTHOST_FREQ_EXTENSION;
116 LibAmdPciReadBits (Reg, 15, 1, &ExtendedFrequency, Nb->ConfigHandle);
117 ThisPort->PrvFrequencyCap = ((Frequency | (ExtendedFrequency << HT_FREQUENCY_2800M)) &
118 Nb->NorthBridgeFreqMask (ThisPort->NodeID, Interface, PlatformConfig, Nb));
119 // Check for Internal link restriction not to run at 1000 MHz (but allow lower)
120 if (IsPackageLinkInternal (Nb->GetPackageLink (ThisPort->NodeID, ThisPort->Link, Nb))) {
121 ThisPort->PrvFrequencyCap &= ~(HT_FREQUENCY_LIMIT_1000M & ~HT_FREQUENCY_LIMIT_800M);
123 ThisPort->ClumpingSupport = HT_CLUMPING_DISABLE;
126 /*----------------------------------------------------------------------------------------*/
128 * Change the hardware state for all Links according to the now optimized data in the
129 * port list data structure for link reganging.
131 * @HtNbMethod{::F_SET_LINK_REGANG}
133 * @param[in] Node the node on which to regang a link
134 * @param[in] Link the sublink 0 of the sublink pair to regang
135 * @param[in] Nb this northbridge
148 Reg.AddressValue = MAKE_SBDFO (MakePciSegmentFromNode (Node),
149 MakePciBusFromNode (Node),
150 MakePciDeviceFromNode (Node),
152 REG_HT_LINK_EXT_CONTROL0_0X170 + (4 * Link));
154 LibAmdPciWriteBits (Reg, 0, 0, &Temp, Nb->ConfigHandle);
157 /*----------------------------------------------------------------------------------------*/
159 * Change the hardware state for all Links according to the now optimized data in the
160 * port list data structure for Unit Id Clumping.
162 * @HtNbMethod{::F_SET_LINK_UNITID_CLUMPING}
164 * This applies to the host root of a non-coherent chain.
166 * @param[in] Node the node on which to enable clumping
167 * @param[in] Link the link for which to enable clumping
168 * @param[in] ClumpingEnables the unit id clumping enables
169 * @param[in] Nb this northbridge
172 SetLinkUnitIdClumping (
175 IN UINT32 ClumpingEnables,
181 // Host Unit Ids are not clumped.
182 ASSERT ((ClumpingEnables & 0x3) == 0);
184 Reg.AddressValue = MAKE_SBDFO (MakePciSegmentFromNode (Node),
185 MakePciBusFromNode (Node),
186 MakePciDeviceFromNode (Node),
188 REG_HT_LINK_CLUMPING0_0X110 + (4 * Link));
190 LibAmdPciWriteBits (Reg, 31, 0, &ClumpingEnables, Nb->ConfigHandle);
193 /*----------------------------------------------------------------------------------------*/
195 * Change the hardware state for all Links according to the now optimized data in the
196 * port list data structure for link frequency.
198 * @HtNbMethod{::F_SET_LINK_FREQUENCY}
200 * Handle extended frequencies. For HT3 frequencies, ensure Retry and Scrambling are
201 * set. For HT1, clear them.
203 * @param[in] Node the node on which to set frequency for a link
204 * @param[in] Link the link to set frequency
205 * @param[in] Frequency the frequency to set
206 * @param[in] Nb this northbridge
219 ASSERT ((Frequency >= HT_FREQUENCY_600M && Frequency <= HT_FREQUENCY_3200M)
220 || (Frequency == HT_FREQUENCY_200M) || (Frequency == HT_FREQUENCY_400M));
222 // Handle extended frequencies, 2800 MHz and above. 31 > Frequency > 16 in this case.
223 if (Frequency > HT_FREQUENCY_2600M) {
226 // Clear it if not extended.
229 Reg = Nb->MakeLinkBase (Node, Link, Nb);
230 Reg.Address.Register += HTHOST_FREQ_EXTENSION;
231 LibAmdPciWriteBits (Reg, 0, 0, &Temp, Nb->ConfigHandle);
232 Reg = Nb->MakeLinkBase (Node, Link, Nb);
233 Reg.Address.Register += HTHOST_FREQ_REV_REG;
234 Temp = (Frequency & 0x0F);
235 LibAmdPciWriteBits (Reg, 11, 8, &Temp, Nb->ConfigHandle);
236 // Gen1 = 200Mhz -> 1000MHz, Gen3 = 1200MHz -> 2600MHz
237 if (Frequency > HT_FREQUENCY_1000M) {
238 // Enable for Gen3 frequencies
241 // Disable for Gen1 frequencies
244 // HT3 retry mode enable / disable
245 Reg.AddressValue = MAKE_SBDFO (MakePciSegmentFromNode (Node),
246 MakePciBusFromNode (Node),
247 MakePciDeviceFromNode (Node),
249 REG_HT_LINK_RETRY0_0X130 + (4 * Link));
250 LibAmdPciWriteBits (Reg, 0, 0, &Temp, Nb->ConfigHandle);
251 // and Scrambling enable / disable
252 Reg.AddressValue = MAKE_SBDFO (MakePciSegmentFromNode (Node),
253 MakePciBusFromNode (Node),
254 MakePciDeviceFromNode (Node),
256 REG_HT_LINK_EXT_CONTROL0_0X170 + (4 * Link));
257 LibAmdPciWriteBits (Reg, 3, 3, &Temp, Nb->ConfigHandle);