zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 1 | /* $NoKeywords:$ */ |
| 2 | /** |
| 3 | * @file |
| 4 | * |
| 5 | * PCIe late post initialization. |
| 6 | * |
| 7 | * |
| 8 | * |
| 9 | * @xrefitem bom "File Content Label" "Release Content" |
| 10 | * @e project: AGESA |
| 11 | * @e sub-project: GNB |
| 12 | * @e \$Revision: 65199 $ @e \$Date: 2012-02-09 21:36:06 -0600 (Thu, 09 Feb 2012) $ |
| 13 | * |
| 14 | */ |
| 15 | /* |
| 16 | ***************************************************************************** |
| 17 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 18 | * Copyright (c) 2008 - 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. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 42 | * *************************************************************************** |
| 43 | * |
| 44 | */ |
| 45 | /*---------------------------------------------------------------------------------------- |
| 46 | * M O D U L E S U S E D |
| 47 | *---------------------------------------------------------------------------------------- |
| 48 | */ |
| 49 | #include "AGESA.h" |
| 50 | #include "Ids.h" |
| 51 | #include "amdlib.h" |
| 52 | #include "Gnb.h" |
| 53 | #include "GnbGfx.h" |
| 54 | #include "GnbPcie.h" |
| 55 | #include "GnbCommonLib.h" |
| 56 | #include "GnbGfxConfig.h" |
| 57 | #include "GnbGfxInitLibV1.h" |
| 58 | #include "GnbNbInitLibV1.h" |
| 59 | #include "GnbGfxFamServices.h" |
| 60 | #include "GfxLibTN.h" |
| 61 | #include "GfxGmcInitTN.h" |
| 62 | #include "GnbRegisterAccTN.h" |
| 63 | #include "GnbRegistersTN.h" |
| 64 | #include "PcieConfigData.h" |
| 65 | #include "PcieConfigLib.h" |
| 66 | #include "cpuFamilyTranslation.h" |
| 67 | #include "GnbHandleLib.h" |
| 68 | #include "Filecode.h" |
| 69 | #define FILECODE PROC_GNB_MODULES_GNBINITTN_GFXMIDINITTN_FILECODE |
| 70 | /*---------------------------------------------------------------------------------------- |
| 71 | * D E F I N I T I O N S A N D M A C R O S |
| 72 | *---------------------------------------------------------------------------------------- |
| 73 | */ |
| 74 | |
| 75 | |
| 76 | /*---------------------------------------------------------------------------------------- |
| 77 | * T Y P E D E F S A N D S T R U C T U R E S |
| 78 | *---------------------------------------------------------------------------------------- |
| 79 | */ |
| 80 | |
| 81 | |
| 82 | /*---------------------------------------------------------------------------------------- |
| 83 | * P R O T O T Y P E S O F L O C A L F U N C T I O N S |
| 84 | *---------------------------------------------------------------------------------------- |
| 85 | */ |
| 86 | AGESA_STATUS |
| 87 | GfxIntegratedEnumerateAudioConnectors ( |
| 88 | IN GFX_PLATFORM_CONFIG *Gfx |
| 89 | ); |
| 90 | |
| 91 | AGESA_STATUS |
| 92 | GfxMidInterfaceTN ( |
| 93 | IN AMD_CONFIG_PARAMS *StdHeader |
| 94 | ); |
| 95 | |
| 96 | VOID |
| 97 | exec803 /* GfxAzWorkaroundTN */ ( |
| 98 | IN GFX_PLATFORM_CONFIG *Gfx |
| 99 | ); |
| 100 | /*----------------------------------------------------------------------------------------*/ |
| 101 | /** |
| 102 | * Set boot up voltage |
| 103 | * |
| 104 | * |
| 105 | * @param[in] Gfx Pointer to global GFX configuration |
| 106 | * @retval AGESA_STATUS |
| 107 | */ |
| 108 | |
| 109 | STATIC AGESA_STATUS |
| 110 | GfxSetBootUpVoltageTN ( |
| 111 | IN GFX_PLATFORM_CONFIG *Gfx |
| 112 | ) |
| 113 | { |
| 114 | IDS_HDT_CONSOLE (GNB_TRACE, "GfxSetBootUpVoltageTN Enter\n"); |
| 115 | GfxRequestVoltageTN (GnbLocateHighestVidCode (GnbLibGetHeader (Gfx)), GnbLibGetHeader (Gfx)); |
| 116 | return AGESA_SUCCESS; |
| 117 | } |
| 118 | |
| 119 | /*----------------------------------------------------------------------------------------*/ |
| 120 | /** |
| 121 | * Set boot up voltage |
| 122 | * |
| 123 | * |
| 124 | * @param[in] Gfx Pointer to global GFX configuration |
| 125 | */ |
| 126 | |
| 127 | VOID |
| 128 | exec803 /* GfxAzWorkaroundTN */ ( |
| 129 | IN GFX_PLATFORM_CONFIG *Gfx |
| 130 | ) |
| 131 | { |
| 132 | UINT32 i; |
| 133 | UINT32 Address; |
| 134 | UINT32 Data; |
| 135 | |
| 136 | |
| 137 | Data = 0x156; |
| 138 | for (i = 0; i < 6; i++) { |
| 139 | Address = 0x5E00 + (i * 0x18); |
| 140 | GnbLibMemWrite (Gfx->GmmBase + Address, AccessS3SaveWidth32, &Data, GnbLibGetHeader (Gfx)); |
| 141 | GnbLibMemRMW (Gfx->GmmBase + Address + 4, AccessS3SaveWidth32, 0xFFFFFF00, 0xF0, GnbLibGetHeader (Gfx)); |
| 142 | } |
| 143 | |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | /*----------------------------------------------------------------------------------------*/ |
| 148 | /** |
| 149 | * Init GFX at Mid Post. |
| 150 | * |
| 151 | * |
| 152 | * |
| 153 | * @param[in] StdHeader Standard configuration header |
| 154 | * @retval AGESA_STATUS |
| 155 | */ |
| 156 | |
| 157 | AGESA_STATUS |
| 158 | GfxMidInterfaceTN ( |
| 159 | IN AMD_CONFIG_PARAMS *StdHeader |
| 160 | ) |
| 161 | { |
| 162 | AGESA_STATUS Status; |
| 163 | AGESA_STATUS AgesaStatus; |
| 164 | GFX_PLATFORM_CONFIG *Gfx; |
| 165 | IDS_HDT_CONSOLE (GNB_TRACE, "GfxMidInterfaceTN Enter\n"); |
| 166 | AgesaStatus = AGESA_SUCCESS; |
| 167 | Status = GfxLocateConfigData (StdHeader, &Gfx); |
| 168 | ASSERT (Status == AGESA_SUCCESS); |
| 169 | AGESA_STATUS_UPDATE (Status, AgesaStatus); |
| 170 | if (Status == AGESA_FATAL) { |
| 171 | GfxFmDisableController (StdHeader); |
| 172 | } else { |
| 173 | if (Gfx->UmaInfo.UmaMode != UMA_NONE) { |
| 174 | Status = GfxEnableGmmAccess (Gfx); |
| 175 | ASSERT (Status == AGESA_SUCCESS); |
| 176 | AGESA_STATUS_UPDATE (Status, AgesaStatus); |
| 177 | if (Status != AGESA_SUCCESS) { |
| 178 | // Can not initialize GMM registers going to disable GFX controller |
| 179 | IDS_HDT_CONSOLE (GNB_TRACE, " Fail to establish GMM access\n"); |
| 180 | Gfx->UmaInfo.UmaMode = UMA_NONE; |
| 181 | GfxFmDisableController (StdHeader); |
| 182 | } else { |
| 183 | Status = GfxGmcInitTN (Gfx); |
| 184 | AGESA_STATUS_UPDATE (Status, AgesaStatus); |
| 185 | |
| 186 | Status = GfxSetBootUpVoltageTN (Gfx); |
| 187 | AGESA_STATUS_UPDATE (Status, AgesaStatus); |
| 188 | |
| 189 | Status = GfxInitSsid (Gfx); |
| 190 | AGESA_STATUS_UPDATE (Status, AgesaStatus); |
| 191 | |
| 192 | Status = GfxIntegratedEnumerateAudioConnectors (Gfx); |
| 193 | AGESA_STATUS_UPDATE (Status, AgesaStatus); |
| 194 | |
| 195 | exec803 /* GfxAzWorkaroundTN */ (Gfx); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | IDS_HDT_CONSOLE (GNB_TRACE, "GfxMidInterfaceTN Exit [0x%x]\n", AgesaStatus); |
| 200 | return AgesaStatus; |
| 201 | } |
| 202 | |
| 203 | /*----------------------------------------------------------------------------------------*/ |
| 204 | /** |
| 205 | * Determine number of audio ports for each connector |
| 206 | * |
| 207 | * |
| 208 | * |
| 209 | * @param[in] Engine Engine configuration info |
| 210 | * @param[in,out] Buffer Buffer pointer |
| 211 | * @param[in] Pcie PCIe configuration info |
| 212 | */ |
| 213 | VOID |
| 214 | STATIC |
| 215 | GfxIntegratedAudioEnumCallback ( |
| 216 | IN PCIe_ENGINE_CONFIG *Engine, |
| 217 | IN OUT VOID *Buffer, |
| 218 | IN PCIe_PLATFORM_CONFIG *Pcie |
| 219 | ) |
| 220 | { |
| 221 | UINT8 *AudioCount; |
| 222 | AudioCount = (UINT8*) Buffer; |
| 223 | if (Engine->Type.Ddi.DdiData.ConnectorType == ConnectorTypeHDMI) { |
| 224 | IDS_HDT_CONSOLE (GNB_TRACE, "Found HDMI Connector\n"); |
| 225 | (*AudioCount)++; |
| 226 | } else if (Engine->Type.Ddi.DdiData.ConnectorType == ConnectorTypeDP) { |
| 227 | if ((Engine->Type.Ddi.DdiData.Flags & DDI_DATA_FLAGS_DP1_1_ONLY) == 0) { |
| 228 | IDS_HDT_CONSOLE (GNB_TRACE, "Found DP1.2 Connector\n"); |
| 229 | *AudioCount += 4; |
| 230 | } else { |
| 231 | IDS_HDT_CONSOLE (GNB_TRACE, "Found DP1.1 Connector\n"); |
| 232 | (*AudioCount)++; |
| 233 | } |
| 234 | } |
| 235 | IDS_HDT_CONSOLE (GNB_TRACE, "New AudioCount = %d\n", *AudioCount); |
| 236 | } |
| 237 | |
| 238 | /*----------------------------------------------------------------------------------------*/ |
| 239 | /** |
| 240 | * Enumerate all display connectors with audio capability and configure number of ports |
| 241 | * |
| 242 | * |
| 243 | * |
| 244 | * @param[in] Gfx Gfx configuration info |
| 245 | */ |
| 246 | AGESA_STATUS |
| 247 | GfxIntegratedEnumerateAudioConnectors ( |
| 248 | IN GFX_PLATFORM_CONFIG *Gfx |
| 249 | ) |
| 250 | { |
| 251 | UINT8 AudioCount; |
| 252 | AGESA_STATUS Status; |
| 253 | GMMx5F50_STRUCT GMMx5F50; |
| 254 | PCIe_PLATFORM_CONFIG *Pcie; |
| 255 | IDS_HDT_CONSOLE (GNB_TRACE, "GfxIntegratedEnumerateAudioConnectors Enter\n"); |
| 256 | |
| 257 | Status = PcieLocateConfigurationData (GnbLibGetHeader (Gfx), &Pcie); |
| 258 | if ((Status == AGESA_SUCCESS) && (Gfx->GnbHdAudio != 0)) { |
| 259 | AudioCount = 0; |
| 260 | PcieConfigRunProcForAllEngines ( |
| 261 | DESCRIPTOR_ALLOCATED | DESCRIPTOR_VIRTUAL | DESCRIPTOR_DDI_ENGINE, |
| 262 | GfxIntegratedAudioEnumCallback, |
| 263 | &AudioCount, |
| 264 | Pcie |
| 265 | ); |
| 266 | if (AudioCount > 4) { |
| 267 | AudioCount = 4; |
| 268 | } |
| 269 | GMMx5F50.Value = 0x00; |
| 270 | GMMx5F50.Field.PortConnectivity = (7 - AudioCount); |
| 271 | GMMx5F50.Field.PortConnectivityOverrideEnable = 1; |
| 272 | GnbRegisterWriteTN (GMMx5F50_TYPE, GMMx5F50_ADDRESS, &GMMx5F50.Value, GNB_REG_ACC_FLAG_S3SAVE, GnbLibGetHeader (Gfx)); |
| 273 | } |
| 274 | IDS_HDT_CONSOLE (GNB_TRACE, "GfxIntegratedEnumerateAudioConnectors Exit\n"); |
| 275 | return Status; |
| 276 | } |
| 277 | |