zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 1 | /* $NoKeywords:$ */ |
| 2 | /** |
| 3 | * @file |
| 4 | * |
| 5 | * Supporting services to collect discrete GFX card info |
| 6 | * |
| 7 | * |
| 8 | * |
| 9 | * @xrefitem bom "File Content Label" "Release Content" |
| 10 | * @e project: AGESA |
| 11 | * @e sub-project: GNB |
| 12 | * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $ |
| 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 | /*---------------------------------------------------------------------------------------- |
| 47 | * M O D U L E S U S E D |
| 48 | *---------------------------------------------------------------------------------------- |
| 49 | */ |
| 50 | #include "AGESA.h" |
| 51 | #include "Ids.h" |
| 52 | #include "amdlib.h" |
| 53 | #include "heapManager.h" |
| 54 | #include "Gnb.h" |
| 55 | #include "GnbGfx.h" |
| 56 | #include "GnbCommonLib.h" |
| 57 | #include "GnbGfxInitLibV1.h" |
| 58 | #include "GfxCardInfo.h" |
| 59 | #include "GnbRegistersLN.h" |
| 60 | #include "Filecode.h" |
| 61 | #define FILECODE PROC_GNB_MODULES_GNBGFXINITLIBV1_GNBGFXINITLIBV1_FILECODE |
| 62 | /*---------------------------------------------------------------------------------------- |
| 63 | * D E F I N I T I O N S A N D M A C R O S |
| 64 | *---------------------------------------------------------------------------------------- |
| 65 | */ |
| 66 | |
| 67 | extern BUILD_OPT_CFG UserOptions; |
| 68 | |
| 69 | /*---------------------------------------------------------------------------------------- |
| 70 | * T Y P E D E F S A N D S T R U C T U R E S |
| 71 | *---------------------------------------------------------------------------------------- |
| 72 | */ |
| 73 | |
| 74 | |
| 75 | |
| 76 | /*---------------------------------------------------------------------------------------- |
| 77 | * 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 |
| 78 | *---------------------------------------------------------------------------------------- |
| 79 | */ |
| 80 | |
| 81 | |
| 82 | /*----------------------------------------------------------------------------------------*/ |
| 83 | /** |
| 84 | * Check if GFX controller fused off |
| 85 | * |
| 86 | * |
| 87 | * @param[in] StdHeader Standard configuration header |
| 88 | * @retval TRUE Gfx controller present and available |
| 89 | */ |
| 90 | BOOLEAN |
| 91 | GfxLibIsControllerPresent ( |
| 92 | IN AMD_CONFIG_PARAMS *StdHeader |
| 93 | ) |
| 94 | { |
| 95 | return GnbLibPciIsDevicePresent (MAKE_SBDFO (0, 0, 1, 0, 0), StdHeader); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | /*----------------------------------------------------------------------------------------*/ |
| 100 | /** |
| 101 | * Init Gfx SSID Registers |
| 102 | * |
| 103 | * |
| 104 | * |
| 105 | * @param[in] Gfx Pointer to global GFX configuration |
| 106 | * @retval AGESA_STATUS Always succeeds |
| 107 | */ |
| 108 | |
| 109 | AGESA_STATUS |
| 110 | GfxInitSsid ( |
| 111 | IN GFX_PLATFORM_CONFIG *Gfx |
| 112 | ) |
| 113 | { |
| 114 | AGESA_STATUS Status; |
| 115 | UINT32 TempData; |
| 116 | PCI_ADDR IgpuAddress; |
| 117 | PCI_ADDR HdaudioAddress; |
| 118 | |
| 119 | Status = AGESA_SUCCESS; |
| 120 | TempData = 0; |
| 121 | |
| 122 | IgpuAddress = Gfx->GfxPciAddress; |
| 123 | HdaudioAddress = Gfx->GfxPciAddress; |
| 124 | HdaudioAddress.Address.Function = 1; |
| 125 | |
| 126 | // Set SSID for internal GPU |
| 127 | if (UserOptions.CfgGnbIGPUSSID != 0) { |
| 128 | GnbLibPciRMW ((IgpuAddress.AddressValue | 0x4C), AccessS3SaveWidth32, 0, UserOptions.CfgGnbIGPUSSID, GnbLibGetHeader (Gfx)); |
| 129 | } else { |
| 130 | GnbLibPciRead (IgpuAddress.AddressValue, AccessS3SaveWidth32, &TempData, GnbLibGetHeader (Gfx)); |
| 131 | GnbLibPciRMW ((IgpuAddress.AddressValue | 0x4C), AccessS3SaveWidth32, 0, TempData, GnbLibGetHeader (Gfx)); |
| 132 | } |
| 133 | |
| 134 | // Set SSID for internal HD Audio |
| 135 | if (UserOptions.CfgGnbHDAudioSSID != 0) { |
| 136 | GnbLibPciRMW ((HdaudioAddress.AddressValue | 0x4C), AccessS3SaveWidth32, 0, UserOptions.CfgGnbHDAudioSSID, GnbLibGetHeader (Gfx)); |
| 137 | } else { |
| 138 | GnbLibPciRead (HdaudioAddress.AddressValue, AccessS3SaveWidth32, &TempData, GnbLibGetHeader (Gfx)); |
| 139 | GnbLibPciRMW ((HdaudioAddress.AddressValue | 0x4C), AccessS3SaveWidth32, 0, TempData, GnbLibGetHeader (Gfx)); |
| 140 | } |
| 141 | |
| 142 | return Status; |
| 143 | } |
| 144 | |
| 145 | |
| 146 | /*----------------------------------------------------------------------------------------*/ |
| 147 | /** |
| 148 | * Copy memory content to FB |
| 149 | * |
| 150 | * |
| 151 | * @param[in] Source Pointer to source |
| 152 | * @param[in] FbOffset FB offset |
| 153 | * @param[in] Length The length to copy |
| 154 | * @param[in] Gfx Pointer to global GFX configuration |
| 155 | * |
| 156 | */ |
| 157 | VOID |
| 158 | GfxLibCopyMemToFb ( |
| 159 | IN VOID *Source, |
| 160 | IN UINT32 FbOffset, |
| 161 | IN UINT32 Length, |
| 162 | IN GFX_PLATFORM_CONFIG *Gfx |
| 163 | ) |
| 164 | { |
| 165 | GMMx00_STRUCT GMMx00; |
| 166 | GMMx04_STRUCT GMMx04; |
| 167 | UINT32 Index; |
| 168 | for (Index = 0; Index < Length; Index = Index + 4 ) { |
| 169 | GMMx00.Value = 0x80000000 | (FbOffset + Index); |
| 170 | GMMx04.Value = *(UINT32*) ((UINT8*)Source + Index); |
| 171 | GnbLibMemWrite (Gfx->GmmBase + GMMx00_ADDRESS, AccessWidth32, &GMMx00.Value, GnbLibGetHeader (Gfx)); |
| 172 | GnbLibMemWrite (Gfx->GmmBase + GMMx04_ADDRESS, AccessWidth32, &GMMx04.Value, GnbLibGetHeader (Gfx)); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | |
| 177 | /*----------------------------------------------------------------------------------------*/ |
| 178 | /** |
| 179 | * Set iGpu VGA mode |
| 180 | * |
| 181 | * |
| 182 | * @param[in] Gfx Pointer to global GFX configuration |
| 183 | * |
| 184 | */ |
| 185 | VOID |
| 186 | GfxLibSetiGpuVgaMode ( |
| 187 | IN GFX_PLATFORM_CONFIG *Gfx |
| 188 | ) |
| 189 | { |
| 190 | GnbLibPciIndirectRMW ( |
| 191 | GNB_SBDFO | D0F0x60_ADDRESS, |
| 192 | D0F0x64_x1D_ADDRESS | IOC_WRITE_ENABLE, |
| 193 | AccessS3SaveWidth32, |
| 194 | (UINT32) ~D0F0x64_x1D_VgaEn_MASK, |
| 195 | ((Gfx->iGpuVgaMode == iGpuVgaAdapter) ? 1 : 0) << D0F0x64_x1D_VgaEn_OFFSET, |
| 196 | GnbLibGetHeader (Gfx) |
| 197 | ); |
| 198 | } |