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 "Gnb.h" |
| 54 | #include "GnbGfx.h" |
| 55 | #include "GnbCommonLib.h" |
| 56 | #include "GfxCardInfo.h" |
| 57 | #include "Filecode.h" |
| 58 | #define FILECODE PROC_GNB_MODULES_GNBGFXINITLIBV1_GFXCARDINFO_FILECODE |
| 59 | /*---------------------------------------------------------------------------------------- |
| 60 | * D E F I N I T I O N S A N D M A C R O S |
| 61 | *---------------------------------------------------------------------------------------- |
| 62 | */ |
| 63 | |
| 64 | |
| 65 | /*---------------------------------------------------------------------------------------- |
| 66 | * T Y P E D E F S A N D S T R U C T U R E S |
| 67 | *---------------------------------------------------------------------------------------- |
| 68 | */ |
| 69 | |
| 70 | typedef struct { |
| 71 | GNB_PCI_SCAN_DATA ScanData; |
| 72 | GFX_CARD_CARD_INFO *GfxCardInfo; |
| 73 | PCI_ADDR BaseBridge; |
| 74 | UINT8 BusNumber; |
| 75 | } GFX_SCAN_DATA; |
| 76 | |
| 77 | |
| 78 | /*---------------------------------------------------------------------------------------- |
| 79 | * 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 |
| 80 | *---------------------------------------------------------------------------------------- |
| 81 | */ |
| 82 | |
| 83 | SCAN_STATUS |
| 84 | GfxScanPcieDevice ( |
| 85 | IN PCI_ADDR Device, |
| 86 | IN OUT GNB_PCI_SCAN_DATA *ScanData |
| 87 | ); |
| 88 | |
| 89 | |
| 90 | |
| 91 | /*----------------------------------------------------------------------------------------*/ |
| 92 | /** |
| 93 | * Get information about all discrete GFX card in system |
| 94 | * |
| 95 | * |
| 96 | * |
| 97 | * @param[out] GfxCardInfo Pointer to GFX card info structure |
| 98 | * @param[in] StdHeader Standard configuration header |
| 99 | */ |
| 100 | |
| 101 | VOID |
| 102 | GfxGetDiscreteCardInfo ( |
| 103 | OUT GFX_CARD_CARD_INFO *GfxCardInfo, |
| 104 | IN AMD_CONFIG_PARAMS *StdHeader |
| 105 | ) |
| 106 | { |
| 107 | GFX_SCAN_DATA GfxScanData; |
| 108 | PCI_ADDR Start; |
| 109 | PCI_ADDR End; |
| 110 | IDS_HDT_CONSOLE (GNB_TRACE, "GfxGetDiscreteCardInfo Enter\n"); |
| 111 | Start.AddressValue = MAKE_SBDFO (0, 0, 2, 0, 0); |
| 112 | End.AddressValue = MAKE_SBDFO (0, 0, 0x1f, 7, 0); |
| 113 | GfxScanData.BusNumber = 5; |
| 114 | GfxScanData.ScanData.GnbScanCallback = GfxScanPcieDevice; |
| 115 | GfxScanData.ScanData.StdHeader = StdHeader; |
| 116 | GfxScanData.GfxCardInfo = GfxCardInfo; |
| 117 | GnbLibPciScan (Start, End, &GfxScanData.ScanData); |
| 118 | IDS_HDT_CONSOLE (GNB_TRACE, "GfxGetDiscreteCardInfo Exit\n"); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | /*----------------------------------------------------------------------------------------*/ |
| 123 | /** |
| 124 | * Evaluate device |
| 125 | * |
| 126 | * |
| 127 | * |
| 128 | * @param[in] Device PCI Address |
| 129 | * @param[in,out] ScanData Scan configuration data |
| 130 | * @retval Scan Status of 0 |
| 131 | */ |
| 132 | |
| 133 | SCAN_STATUS |
| 134 | GfxScanPcieDevice ( |
| 135 | IN PCI_ADDR Device, |
| 136 | IN OUT GNB_PCI_SCAN_DATA *ScanData |
| 137 | ) |
| 138 | { |
| 139 | UINT8 ClassCode; |
| 140 | UINT32 VendorId; |
| 141 | |
| 142 | IDS_HDT_CONSOLE (GFX_MISC, " Evaluate device [%d:%d:%d]\n", |
| 143 | Device.Address.Bus, Device.Address.Device, Device.Address.Function |
| 144 | ); |
| 145 | |
| 146 | if (GnbLibPciIsBridgeDevice (Device.AddressValue, ScanData->StdHeader)) { |
| 147 | UINT32 SaveBusConfiguration; |
| 148 | UINT32 Value; |
| 149 | |
| 150 | if (Device.Address.Bus == 0) { |
| 151 | ((GFX_SCAN_DATA *) ScanData)->BaseBridge = Device; |
| 152 | } |
| 153 | GnbLibPciRead (Device.AddressValue | 0x18, AccessWidth32, &SaveBusConfiguration, ScanData->StdHeader); |
| 154 | Value = (((0xFF << 8) | ((GFX_SCAN_DATA *) ScanData)->BusNumber) << 8) | Device.Address.Bus; |
| 155 | GnbLibPciWrite (Device.AddressValue | 0x18, AccessWidth32, &Value, ScanData->StdHeader); |
| 156 | ((GFX_SCAN_DATA *) ScanData)->BusNumber++; |
| 157 | |
| 158 | GnbLibPciScanSecondaryBus (Device, ScanData); |
| 159 | |
| 160 | ((GFX_SCAN_DATA *) ScanData)->BusNumber--; |
| 161 | GnbLibPciWrite (Device.AddressValue | 0x18, AccessWidth32, &SaveBusConfiguration, ScanData->StdHeader); |
| 162 | return 0; |
| 163 | } |
| 164 | GnbLibPciRead (Device.AddressValue | 0x0b, AccessWidth8, &ClassCode, ScanData->StdHeader); |
| 165 | if (ClassCode == 3) { |
| 166 | IDS_HDT_CONSOLE (GFX_MISC, " Found GFX Card\n" |
| 167 | ); |
| 168 | |
| 169 | GnbLibPciRead (Device.AddressValue | 0x00, AccessWidth32, &VendorId, ScanData->StdHeader); |
| 170 | if (!GnbLibPciIsPcieDevice (Device.AddressValue, ScanData->StdHeader)) { |
| 171 | IDS_HDT_CONSOLE (GFX_MISC, " GFX Card is PCI device\n" |
| 172 | ); |
| 173 | ((GFX_SCAN_DATA *) ScanData)->GfxCardInfo->PciGfxCardBitmap |= (1 << ((GFX_SCAN_DATA *) ScanData)->BaseBridge.Address.Device); |
| 174 | return 0; |
| 175 | } |
| 176 | if ((UINT16) VendorId == 0x1002) { |
| 177 | IDS_HDT_CONSOLE (GFX_MISC, " GFX Card is AMD PCIe device\n" |
| 178 | ); |
| 179 | ((GFX_SCAN_DATA *) ScanData)->GfxCardInfo->AmdPcieGfxCardBitmap |= (1 << ((GFX_SCAN_DATA *) ScanData)->BaseBridge.Address.Device); |
| 180 | } |
| 181 | ((GFX_SCAN_DATA *) ScanData)->GfxCardInfo->PcieGfxCardBitmap |= (1 << ((GFX_SCAN_DATA *) ScanData)->BaseBridge.Address.Device); |
| 182 | } |
| 183 | return 0; |
| 184 | } |