AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / HT / Fam10 / htNbOptimizationFam10.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * Link optimization support specific to family 10h processors.
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 "Ids.h"
56 #include "Topology.h"
57 #include "htFeat.h"
58 #include "htInterface.h"
59 #include "htNb.h"
60 #include "htNbOptimizationFam10.h"
61 #include "Filecode.h"
62 CODE_GROUP (G1_PEICC)
63 RDATA_GROUP (G2_PEI)
64
65 #define FILECODE PROC_HT_FAM10_HTNBOPTIMIZATIONFAM10_FILECODE
66 /*----------------------------------------------------------------------------
67  *                          DEFINITIONS AND MACROS
68  *
69  *----------------------------------------------------------------------------
70  */
71
72 /*----------------------------------------------------------------------------------------*/
73 /**
74  * Northbridge specific Frequency limit.
75  *
76  * @HtNbMethod{::F_NORTH_BRIDGE_FREQ_MASK}
77  *
78  * Return a mask that eliminates HT frequencies that cannot be used due to a slow
79  * northbridge frequency.
80  *
81  * @param[in]     Node             Result could (later) be for a specific Node
82  * @param[in]     Interface        Access to non-HT support functions.
83  * @param[in]     PlatformConfig   Platform profile/build option config structure.
84  * @param[in]     Nb               this northbridge
85  *
86  * @return Frequency mask
87  */
88 UINT32
89 Fam10NorthBridgeFreqMask (
90   IN       UINT8                  Node,
91   IN       HT_INTERFACE           *Interface,
92   IN       PLATFORM_CONFIGURATION *PlatformConfig,
93   IN       NORTHBRIDGE            *Nb
94   )
95 {
96   UINT32 NbCoreFreq;
97   UINT32 Supported;
98
99   ASSERT (Node < MAX_NODES);
100   ASSERT (Interface != NULL);
101   // The interface to power management will return a system based result.
102   // So we only need to call it once, not on every link.  Save the answer,
103   // and check to see if we can use a saved answer on subsequent calls.
104   //
105   if (Nb->CoreFrequency == 0) {
106     NbCoreFreq = Interface->GetMinNbCoreFreq (PlatformConfig, Nb->ConfigHandle);
107     NbCoreFreq = (NbCoreFreq / 100);
108     ASSERT (NbCoreFreq != 0);
109     Nb->CoreFrequency = NbCoreFreq;
110   } else {
111     NbCoreFreq = Nb->CoreFrequency;
112   }
113
114   //
115   // NbCoreFreq is minimum northbridge speed in hundreds of MHz.
116   // HT can not go faster than the minimum speed of the northbridge.
117   //
118   if ((NbCoreFreq >= 6) && (NbCoreFreq <= 26)) {
119     //  Convert frequency to bit and all less significant bits,
120     // by setting next power of 2 and subtracting 1.
121     //
122     Supported = ((UINT32)1 << ((NbCoreFreq >> 1) + 2)) - 1;
123   } else if ((NbCoreFreq > 26) && (NbCoreFreq <= 32)) {
124     // Convert frequency to bit and all less significant bits,
125     // by setting next power of 2 and subtracting 1, noting that
126     // next power of two is two greater than non-extended frequencies
127     // (because of the register break).
128     //
129     Supported = ((UINT32)1 << ((NbCoreFreq >> 1) + 4)) - 1;
130   } else if (NbCoreFreq > 32) {
131     Supported = HT_FREQUENCY_LIMIT_MAX;
132   } else if (NbCoreFreq == 4) {
133     // unlikely cases, but include as a defensive measure, also avoid trick above
134     Supported = HT_FREQUENCY_LIMIT_400M;
135   } else if (NbCoreFreq == 2) {
136     Supported = HT_FREQUENCY_LIMIT_200M;
137   } else {
138     ASSERT (FALSE);
139     Supported = HT_FREQUENCY_LIMIT_200M;
140   }
141
142   return (Supported);
143 }
144
145 /*----------------------------------------------------------------------------------------*/
146 /**
147  * Northbridge specific Frequency limit.
148  *
149  * @HtNbMethod{::F_NORTH_BRIDGE_FREQ_MASK}
150  *
151  * Return a mask that eliminates HT frequencies that cannot be used due to a slow
152  * northbridge frequency.
153  *
154  * @param[in]     Node             Result could (later) be for a specific Node
155  * @param[in]     Interface        Access to non-HT support functions.
156  * @param[in]     PlatformConfig   Platform profile/build option config structure.
157  * @param[in]     Nb               this northbridge
158  *
159  * @return Frequency mask
160  */
161 UINT32
162 Fam10RevDNorthBridgeFreqMask (
163   IN       UINT8                  Node,
164   IN       HT_INTERFACE           *Interface,
165   IN       PLATFORM_CONFIGURATION *PlatformConfig,
166   IN       NORTHBRIDGE            *Nb
167   )
168 {
169   UINT32 NbCoreFreq;
170   UINT32 Supported;
171
172   ASSERT (Node < MAX_NODES);
173   ASSERT (Interface != NULL);
174   // The interface to power management will return a system based result.
175   // So we only need to call it once, not on every link.  Save the answer,
176   // and check to see if we can use a saved answer on subsequent calls.
177   //
178   if (Nb->CoreFrequency == 0) {
179     NbCoreFreq = Interface->GetMinNbCoreFreq (PlatformConfig, Nb->ConfigHandle);
180     NbCoreFreq = (NbCoreFreq / 100);
181     ASSERT (NbCoreFreq != 0);
182     Nb->CoreFrequency = NbCoreFreq;
183   } else {
184     NbCoreFreq = Nb->CoreFrequency;
185   }
186
187   // For Rev D, the Ht frequency can go twice the Nb COF, as long as it's HT3.
188   // (side note: we are not speculatively upgrading HT1 at 6 .. 10 to HT3,
189   //  to avoid complicated recovery if the final speed is HT1.)
190   if (NbCoreFreq > 10) {
191     NbCoreFreq = NbCoreFreq * 2;
192   }
193   //
194   // NbCoreFreq is minimum northbridge speed in hundreds of MHz.
195   // HT can not go faster than the minimum speed of the northbridge.
196   //
197   if ((NbCoreFreq >= 6) && (NbCoreFreq <= 26)) {
198     //  Convert frequency to bit and all less significant bits,
199     // by setting next power of 2 and subtracting 1.
200     //
201     Supported = ((UINT32)1 << ((NbCoreFreq >> 1) + 2)) - 1;
202   } else if ((NbCoreFreq > 26) && (NbCoreFreq <= 32)) {
203     // Convert frequency to bit and all less significant bits,
204     // by setting next power of 2 and subtracting 1, noting that
205     // next power of two is two greater than non-extended frequencies
206     // (because of the register break).
207     //
208     Supported = ((UINT32)1 << ((NbCoreFreq >> 1) + 4)) - 1;
209   } else if (NbCoreFreq > 32) {
210     Supported = HT_FREQUENCY_LIMIT_MAX;
211   } else if (NbCoreFreq == 4) {
212     // unlikely cases, but include as a defensive measure, also avoid trick above
213     Supported = HT_FREQUENCY_LIMIT_400M;
214   } else if (NbCoreFreq == 2) {
215     Supported = HT_FREQUENCY_LIMIT_200M;
216   } else {
217     ASSERT (FALSE);
218     Supported = HT_FREQUENCY_LIMIT_200M;
219   }
220
221   return (Supported);
222 }