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