AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / HT / htNb.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * Construct a northbridge interface for a Node.
6  *
7  * Handle build options and run-time detection.
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  HyperTransport
12  * @e \$Revision: 56279 $   @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
13  *
14  */
15 /*
16 *****************************************************************************
17 *
18 * Copyright (C) 2012 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  *----------------------------------------------------------------------------
49  *                                MODULES USED
50  *
51  *----------------------------------------------------------------------------
52  */
53
54 #include "AGESA.h"
55 #include "amdlib.h"
56 #include "OptionsHt.h"
57 #include "Ids.h"
58 #include "Topology.h"
59 #include "htFeat.h"
60 #include "htNb.h"
61 #include "htNbCommonHardware.h"
62 #include "CommonReturns.h"
63 #include "cpuRegisters.h"
64 #include "cpuFamilyTranslation.h"
65 #include "cpuFamRegisters.h"
66 CODE_GROUP (G1_PEICC)
67 RDATA_GROUP (G2_PEI)
68
69 #include "Filecode.h"
70
71 #define FILECODE PROC_HT_HTNB_FILECODE
72
73 extern OPTION_HT_CONFIGURATION OptionHtConfiguration;
74
75 /*----------------------------------------------------------------------------
76  *                          DEFINITIONS AND MACROS
77  *
78  *----------------------------------------------------------------------------
79  */
80
81 /*----------------------------------------------------------------------------
82  *                           TYPEDEFS AND STRUCTURES
83  *
84  *----------------------------------------------------------------------------
85  */
86 /*----------------------------------------------------------------------------
87  *                        PROTOTYPES OF LOCAL FUNCTIONS
88  *
89  *----------------------------------------------------------------------------
90  */
91
92 /***************************************************************************
93  ***               FAMILY/NORTHBRIDGE SPECIFIC FUNCTIONS                 ***
94  ***************************************************************************/
95
96
97 /**
98  * Initial construction data for no HT Northbridge.
99  */
100 CONST NORTHBRIDGE ROMDATA HtFam10NbNone =
101 {
102   1,
103   (PF_WRITE_ROUTING_TABLE)CommonVoid,
104   (PF_WRITE_NODEID)CommonVoid,
105   (PF_READ_DEFAULT_LINK)CommonReturnZero8,
106   (PF_ENABLE_ROUTING_TABLES)CommonVoid,
107   (PF_DISABLE_ROUTING_TABLES)CommonVoid,
108   (PF_VERIFY_LINK_IS_COHERENT)CommonReturnFalse,
109   (PF_READ_TOKEN)CommonReturnZero8,
110   (PF_WRITE_TOKEN)CommonVoid,
111   (PF_WRITE_FULL_ROUTING_TABLE)CommonVoid,
112   (PF_IS_ILLEGAL_TYPE_MIX)CommonReturnFalse,
113   (PF_IS_EXCEEDED_CAPABLE)CommonReturnFalse,
114   (PF_STOP_LINK)CommonVoid,
115   (PF_HANDLE_SPECIAL_LINK_CASE)CommonReturnFalse,
116   (PF_HANDLE_SPECIAL_NODE_CASE)CommonReturnFalse,
117   (PF_READ_SB_LINK)CommonReturnZero8,
118   (PF_VERIFY_LINK_IS_NON_COHERENT)CommonReturnFalse,
119   (PF_SET_CONFIG_ADDR_MAP)CommonVoid,
120   (PF_NORTH_BRIDGE_FREQ_MASK)CommonReturnZero32,
121   (PF_GATHER_LINK_FEATURES)CommonVoid,
122   (PF_SET_LINK_REGANG)CommonVoid,
123   (PF_SET_LINK_FREQUENCY)CommonVoid,
124   (PF_SET_LINK_UNITID_CLUMPING)CommonVoid,
125   (PF_WRITE_TRAFFIC_DISTRIBUTION)CommonVoid,
126   (PF_WRITE_LINK_PAIR_DISTRIBUTION)CommonVoid,
127   (PF_WRITE_VICTIM_DISTRIBUTION)CommonVoid,
128   (PF_BUFFER_OPTIMIZATIONS)CommonVoid,
129   (PF_GET_NUM_CORES_ON_NODE)CommonReturnZero8,
130   (PF_SET_TOTAL_NODES_AND_CORES)CommonVoid,
131   (PF_GET_NODE_COUNT)CommonReturnZero8,
132   (PF_LIMIT_NODES)CommonVoid,
133   (PF_READ_TRUE_LINK_FAIL_STATUS)CommonReturnFalse,
134   (PF_GET_NEXT_LINK)CommonReturnZero32,
135   (PF_GET_PACKAGE_LINK)CommonReturnZero8,
136   (PF_MAKE_LINK_BASE)CommonReturnZero32,
137   (PF_GET_MODULE_INFO)CommonVoid,
138   (PF_POST_MAILBOX)CommonVoid,
139   (PF_RETRIEVE_MAILBOX)CommonReturnZero32,
140   (PF_GET_SOCKET)CommonReturnZero8,
141   (PF_GET_ENABLED_COMPUTE_UNITS)CommonReturnZero8,
142   (PF_GET_DUALCORE_COMPUTE_UNITS)CommonReturnZero8,
143   0,
144   0,
145   0,
146   TRUE,
147   TRUE,
148   0,
149   NULL,
150   0,
151   NULL,
152   (PF_MAKE_KEY)CommonReturnZero64,
153   NULL
154 };
155
156 /*----------------------------------------------------------------------------------------*/
157 /**
158  * Make a compatibility key.
159  *
160  * @HtNbMethod{::F_MAKE_KEY}
161  *
162  * Private routine to northbridge code.
163  * Create a key which can be used to determine whether a Node is compatible with
164  * the discovered configuration so far.  Currently, that means the family,
165  * extended family of the new Node are the same as the BSP's.  Family specific
166  * implementations can add whatever else is necessary.
167  *
168  * @param[in] Node the Node
169  * @param[in] Nb   this northbridge
170  *
171  * @return the key
172  */
173 UINT64
174 MakeKey (
175   IN       UINT8 Node,
176   IN       NORTHBRIDGE *Nb
177   )
178 {
179   CPU_LOGICAL_ID LogicalId;
180   UINT32 RawCpuId;
181   PCI_ADDR Reg;
182
183   Reg.AddressValue = MAKE_SBDFO (MakePciSegmentFromNode (Node),
184                                  MakePciBusFromNode (Node),
185                                  MakePciDeviceFromNode (Node),
186                                  CPU_NB_FUNC_03,
187                                  REG_NB_CPUID_3XFC);
188
189   LibAmdPciReadBits (Reg, 31, 0, &RawCpuId, Nb->ConfigHandle);
190   GetLogicalIdFromCpuid (RawCpuId, &LogicalId, Nb->ConfigHandle);
191   return LogicalId.Family;
192 }
193
194 /*----------------------------------------------------------------------------------------*/
195 /**
196  * Construct a new northbridge.
197  *
198  * This routine encapsulates knowledge of how to tell significant differences between
199  * families of supported northbridges and what routines can be used in common and
200  * which are unique.  A fully populated northbridge interface is provided by Nb.
201  *
202  * @param[in]     Node    create a northbridge interface for this Node.
203  * @param[in]     State   global state
204  * @param[out]    Nb      the caller's northbridge structure to initialize.
205  */
206 VOID
207 NewNorthBridge (
208   IN       UINT8       Node,
209   IN       STATE_DATA  *State,
210      OUT   NORTHBRIDGE *Nb
211   )
212 {
213   CPU_LOGICAL_ID LogicalId;
214   UINT64  Match;
215   UINT32 RawCpuId;
216   PCI_ADDR Reg;
217   NORTHBRIDGE **InitializerInstance;
218
219   // Start with enough of the key to identify the northbridge interface
220   Reg.AddressValue = MAKE_SBDFO (MakePciSegmentFromNode (Node),
221                                  MakePciBusFromNode (Node),
222                                  MakePciDeviceFromNode (Node),
223                                  CPU_NB_FUNC_03,
224                                  REG_NB_CPUID_3XFC);
225   LibAmdPciReadBits (Reg, 31, 0, &RawCpuId, State->ConfigHandle);
226   IDS_HDT_CONSOLE (HT_TRACE, "AMD Processor at Node %d has raw CPUID=%x.\n", Node, RawCpuId);
227   GetLogicalIdFromCpuid (RawCpuId, &LogicalId, State->ConfigHandle);
228   Match = LogicalId.Family;
229
230   // Test each Northbridge interface in turn looking for a match.
231   // Use it to Init the Nb struct if a match is found.
232   //
233   ASSERT (OptionHtConfiguration.HtOptionFamilyNorthbridgeList != NULL);
234   InitializerInstance = (NORTHBRIDGE **) (OptionHtConfiguration.HtOptionFamilyNorthbridgeList);
235   while (*InitializerInstance != NULL) {
236     if ((Match & (*InitializerInstance)->CompatibleKey) != 0) {
237       LibAmdMemCopy ((VOID *)Nb, (VOID *)*InitializerInstance, (UINT32) sizeof (NORTHBRIDGE), State->ConfigHandle);
238       break;
239     }
240     InitializerInstance++;
241   }
242   // There must be an available northbridge implementation.
243   ASSERT (*InitializerInstance != NULL);
244
245   // Set the config handle for passing to the library.
246   Nb->ConfigHandle = State->ConfigHandle;
247 }
248