AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / HT / NbCommon / htNbOptimization.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * Link optimization support.
6  *
7  * @xrefitem bom "File Content Label" "Release Content"
8  * @e project:      AGESA
9  * @e sub-project:  HyperTransport
10  * @e \$Revision: 56279 $   @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
11  *
12  */
13 /*
14 *****************************************************************************
15 *
16 * Copyright (C) 2012 Advanced Micro Devices, Inc.
17 * All rights reserved.
18 *
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.
29 *
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.
40 *
41 * ***************************************************************************
42 *
43 */
44
45 /*
46  *----------------------------------------------------------------------------
47  *                                MODULES USED
48  *
49  *----------------------------------------------------------------------------
50  */
51
52
53
54 #include "AGESA.h"
55 #include "amdlib.h"
56 #include "Ids.h"
57 #include "Topology.h"
58 #include "htFeat.h"
59 #include "IdsHt.h"
60 #include "htInterface.h"
61 #include "htInterfaceGeneral.h"
62 #include "htNotify.h"
63 #include "htNb.h"
64 #include "htNbCommonHardware.h"
65 #include "htNbOptimization.h"
66 #include "Filecode.h"
67 CODE_GROUP (G1_PEICC)
68 RDATA_GROUP (G2_PEI)
69
70 #define FILECODE PROC_HT_NBCOMMON_HTNBOPTIMIZATION_FILECODE
71 /*----------------------------------------------------------------------------
72  *                          DEFINITIONS AND MACROS
73  *
74  *----------------------------------------------------------------------------
75  */
76
77 /***************************************************************************
78  ***                            Link Optimization                        ***
79  ***************************************************************************/
80
81 /*----------------------------------------------------------------------------------------*/
82 /**
83  * Get Link features into system data structure.
84  *
85  * @HtNbMethod{::F_GATHER_LINK_FEATURES}
86  *
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,
90  *   it just means:
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.
93  *
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
98  */
99 VOID
100 GatherLinkFeatures (
101   IN OUT   PORT_DESCRIPTOR        *ThisPort,
102   IN       HT_INTERFACE           *Interface,
103   IN       PLATFORM_CONFIGURATION *PlatformConfig,
104   IN       NORTHBRIDGE            *Nb
105   )
106 {
107   PCI_ADDR Reg;
108   UINT32 Frequency;
109   UINT32 ExtendedFrequency;
110
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);
122   }
123   ThisPort->ClumpingSupport = HT_CLUMPING_DISABLE;
124 }
125
126 /*----------------------------------------------------------------------------------------*/
127 /**
128  * Change the hardware state for all Links according to the now optimized data in the
129  * port list data structure for link reganging.
130  *
131  * @HtNbMethod{::F_SET_LINK_REGANG}
132  *
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
136  */
137 VOID
138 SetLinkRegang (
139   IN       UINT8       Node,
140   IN       UINT8       Link,
141   IN       NORTHBRIDGE *Nb
142   )
143 {
144   PCI_ADDR Reg;
145   UINT32 Temp;
146
147   Temp = 1;
148   Reg.AddressValue = MAKE_SBDFO (MakePciSegmentFromNode (Node),
149                                  MakePciBusFromNode (Node),
150                                  MakePciDeviceFromNode (Node),
151                                  CPU_HTNB_FUNC_00,
152                                  REG_HT_LINK_EXT_CONTROL0_0X170 + (4 * Link));
153
154   LibAmdPciWriteBits (Reg, 0, 0, &Temp, Nb->ConfigHandle);
155 }
156
157 /*----------------------------------------------------------------------------------------*/
158 /**
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.
161  *
162  * @HtNbMethod{::F_SET_LINK_UNITID_CLUMPING}
163  *
164  * This applies to the host root of a non-coherent chain.
165  *
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
170  */
171 VOID
172 SetLinkUnitIdClumping (
173   IN       UINT8       Node,
174   IN       UINT8       Link,
175   IN       UINT32      ClumpingEnables,
176   IN       NORTHBRIDGE *Nb
177   )
178 {
179   PCI_ADDR Reg;
180
181   // Host Unit Ids are not clumped.
182   ASSERT ((ClumpingEnables & 0x3) == 0);
183
184   Reg.AddressValue = MAKE_SBDFO (MakePciSegmentFromNode (Node),
185                                  MakePciBusFromNode (Node),
186                                  MakePciDeviceFromNode (Node),
187                                  CPU_HTNB_FUNC_00,
188                                  REG_HT_LINK_CLUMPING0_0X110 + (4 * Link));
189
190   LibAmdPciWriteBits (Reg, 31, 0, &ClumpingEnables, Nb->ConfigHandle);
191 }
192
193 /*----------------------------------------------------------------------------------------*/
194 /**
195  * Change the hardware state for all Links according to the now optimized data in the
196  * port list data structure for link frequency.
197  *
198  * @HtNbMethod{::F_SET_LINK_FREQUENCY}
199  *
200  * Handle extended frequencies.  For HT3 frequencies, ensure Retry and Scrambling are
201  * set. For HT1, clear them.
202  *
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
207  */
208 VOID
209 SetLinkFrequency (
210   IN       UINT8          Node,
211   IN       UINT8          Link,
212   IN       UINT8          Frequency,
213   IN       NORTHBRIDGE    *Nb
214   )
215 {
216   UINT32 Temp;
217   PCI_ADDR Reg;
218
219   ASSERT ((Frequency >= HT_FREQUENCY_600M && Frequency <= HT_FREQUENCY_3200M)
220           || (Frequency == HT_FREQUENCY_200M) || (Frequency == HT_FREQUENCY_400M));
221
222   // Handle extended frequencies, 2800 MHz and above.  31 > Frequency > 16 in this case.
223   if (Frequency > HT_FREQUENCY_2600M) {
224     Temp = 1;
225   } else {
226     // Clear it if not extended.
227     Temp = 0;
228   }
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
239     Temp = 1;
240   } else {
241     // Disable  for Gen1 frequencies
242     Temp = 0;
243   }
244   // HT3 retry mode enable / disable
245   Reg.AddressValue = MAKE_SBDFO (MakePciSegmentFromNode (Node),
246                                  MakePciBusFromNode (Node),
247                                  MakePciDeviceFromNode (Node),
248                                  CPU_HTNB_FUNC_00,
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),
255                                  CPU_HTNB_FUNC_00,
256                                  REG_HT_LINK_EXT_CONTROL0_0X170 + (4 * Link));
257   LibAmdPciWriteBits (Reg, 3, 3, &Temp, Nb->ConfigHandle);
258 }