Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 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: 35978 $ @e \$Date: 2010-08-07 02:18:50 +0800 (Sat, 07 Aug 2010) $ |
| 13 | * |
| 14 | */ |
| 15 | /* |
| 16 | ***************************************************************************** |
| 17 | * |
| 18 | * Copyright (c) 2011, Advanced Micro Devices, Inc. |
| 19 | * All rights reserved. |
Edward O'Callaghan | 1542a6f | 2014-07-06 19:24:06 +1000 | [diff] [blame] | 20 | * |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 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. |
Edward O'Callaghan | 1542a6f | 2014-07-06 19:24:06 +1000 | [diff] [blame] | 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 |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 30 | * from this software without specific prior written permission. |
Edward O'Callaghan | 1542a6f | 2014-07-06 19:24:06 +1000 | [diff] [blame] | 31 | * |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 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. |
Edward O'Callaghan | 1542a6f | 2014-07-06 19:24:06 +1000 | [diff] [blame] | 42 | * |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 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 "htNbHardwareFam10.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 (G1_PEICC) |
| 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_BUFFER_OPTIMIZATIONS)CommonVoid, |
| 128 | (PF_GET_NUM_CORES_ON_NODE)CommonReturnZero8, |
| 129 | (PF_SET_TOTAL_NODES_AND_CORES)CommonVoid, |
| 130 | (PF_GET_NODE_COUNT)CommonReturnZero8, |
| 131 | (PF_LIMIT_NODES)CommonVoid, |
| 132 | (PF_READ_TRUE_LINK_FAIL_STATUS)CommonReturnFalse, |
| 133 | (PF_GET_NEXT_LINK)CommonReturnZero32, |
| 134 | (PF_GET_PACKAGE_LINK)CommonReturnZero8, |
| 135 | (PF_MAKE_LINK_BASE)CommonReturnZero32, |
| 136 | (PF_GET_MODULE_INFO)CommonVoid, |
| 137 | (PF_POST_MAILBOX)CommonVoid, |
| 138 | (PF_RETRIEVE_MAILBOX)CommonReturnZero32, |
| 139 | (PF_GET_SOCKET)CommonReturnZero8, |
| 140 | (PF_GET_ENABLED_COMPUTE_UNITS)CommonReturnZero8, |
| 141 | (PF_GET_DUALCORE_COMPUTE_UNITS)CommonReturnZero8, |
| 142 | 0, |
| 143 | 0, |
| 144 | 0, |
| 145 | TRUE, |
| 146 | TRUE, |
| 147 | 0, |
| 148 | NULL, |
| 149 | 0, |
| 150 | NULL, |
| 151 | (PF_MAKE_KEY)CommonReturnZero64, |
| 152 | NULL |
| 153 | }; |
| 154 | |
| 155 | /*----------------------------------------------------------------------------------------*/ |
| 156 | /** |
| 157 | * Make a compatibility key. |
| 158 | * |
| 159 | * @HtNbMethod{::F_MAKE_KEY} |
| 160 | * |
| 161 | * Private routine to northbridge code. |
| 162 | * Create a key which can be used to determine whether a Node is compatible with |
| 163 | * the discovered configuration so far. Currently, that means the family, |
| 164 | * extended family of the new Node are the same as the BSP's. Family specific |
| 165 | * implementations can add whatever else is necessary. |
| 166 | * |
| 167 | * @param[in] Node the Node |
| 168 | * @param[in] Nb this northbridge |
| 169 | * |
| 170 | * @return the key |
| 171 | */ |
| 172 | UINT64 |
| 173 | MakeKey ( |
| 174 | IN UINT8 Node, |
| 175 | IN NORTHBRIDGE *Nb |
| 176 | ) |
| 177 | { |
| 178 | CPU_LOGICAL_ID LogicalId; |
| 179 | UINT32 RawCpuId; |
| 180 | PCI_ADDR Reg; |
| 181 | |
| 182 | Reg.AddressValue = MAKE_SBDFO (MakePciSegmentFromNode (Node), |
| 183 | MakePciBusFromNode (Node), |
| 184 | MakePciDeviceFromNode (Node), |
| 185 | CPU_NB_FUNC_03, |
| 186 | REG_NB_CPUID_3XFC); |
| 187 | |
| 188 | LibAmdPciReadBits (Reg, 31, 0, &RawCpuId, Nb->ConfigHandle); |
| 189 | GetLogicalIdFromCpuid (RawCpuId, &LogicalId, Nb->ConfigHandle); |
| 190 | return LogicalId.Family; |
| 191 | } |
| 192 | |
| 193 | /*----------------------------------------------------------------------------------------*/ |
| 194 | /** |
| 195 | * Construct a new northbridge. |
| 196 | * |
| 197 | * This routine encapsulates knowledge of how to tell significant differences between |
| 198 | * families of supported northbridges and what routines can be used in common and |
| 199 | * which are unique. A fully populated northbridge interface is provided by Nb. |
| 200 | * |
| 201 | * @param[in] Node create a northbridge interface for this Node. |
| 202 | * @param[in] State global state |
| 203 | * @param[out] Nb the caller's northbridge structure to initialize. |
| 204 | */ |
| 205 | VOID |
| 206 | NewNorthBridge ( |
| 207 | IN UINT8 Node, |
| 208 | IN STATE_DATA *State, |
| 209 | OUT NORTHBRIDGE *Nb |
| 210 | ) |
| 211 | { |
| 212 | CPU_LOGICAL_ID LogicalId; |
| 213 | UINT64 Match; |
| 214 | UINT32 RawCpuId; |
| 215 | PCI_ADDR Reg; |
| 216 | NORTHBRIDGE **InitializerInstance; |
| 217 | |
| 218 | // Start with enough of the key to identify the northbridge interface |
| 219 | Reg.AddressValue = MAKE_SBDFO (MakePciSegmentFromNode (Node), |
| 220 | MakePciBusFromNode (Node), |
| 221 | MakePciDeviceFromNode (Node), |
| 222 | CPU_NB_FUNC_03, |
| 223 | REG_NB_CPUID_3XFC); |
| 224 | LibAmdPciReadBits (Reg, 31, 0, &RawCpuId, State->ConfigHandle); |
| 225 | IDS_HDT_CONSOLE (HT_TRACE, "AMD Processor at Node %d has raw CPUID=%x.\n", Node, RawCpuId); |
| 226 | GetLogicalIdFromCpuid (RawCpuId, &LogicalId, State->ConfigHandle); |
| 227 | Match = LogicalId.Family; |
| 228 | |
| 229 | // Test each Northbridge interface in turn looking for a match. |
| 230 | // Use it to Init the Nb struct if a match is found. |
| 231 | // |
| 232 | ASSERT (OptionHtConfiguration.HtOptionFamilyNorthbridgeList != NULL); |
| 233 | InitializerInstance = (NORTHBRIDGE **) (OptionHtConfiguration.HtOptionFamilyNorthbridgeList); |
| 234 | while (*InitializerInstance != NULL) { |
| 235 | if ((Match & (*InitializerInstance)->CompatibleKey) != 0) { |
| 236 | LibAmdMemCopy ((VOID *)Nb, (VOID *)*InitializerInstance, (UINT32) sizeof (NORTHBRIDGE), State->ConfigHandle); |
| 237 | break; |
| 238 | } |
| 239 | InitializerInstance++; |
| 240 | } |
| 241 | // There must be an available northbridge implementation. |
| 242 | ASSERT (*InitializerInstance != NULL); |
| 243 | |
| 244 | // Set the config handle for passing to the library. |
| 245 | Nb->ConfigHandle = State->ConfigHandle; |
| 246 | } |
| 247 | |