zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 1 | /* $NoKeywords:$ */ |
| 2 | /** |
| 3 | * @file |
| 4 | * |
| 5 | * GNB UNB library |
| 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 "cpuServices.h" |
| 54 | #include "Gnb.h" |
| 55 | #include "GnbCommonLib.h" |
| 56 | #include "GnbFamServices.h" |
| 57 | #include "GnbPcieConfig.h" |
| 58 | #include "Filecode.h" |
| 59 | #define FILECODE PROC_GNB_MODULES_GNBMSOCKETLIB_GNBMSOCKETLIB_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 | |
| 72 | /*---------------------------------------------------------------------------------------- |
| 73 | * 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 |
| 74 | *---------------------------------------------------------------------------------------- |
| 75 | */ |
| 76 | |
| 77 | |
| 78 | |
| 79 | /*----------------------------------------------------------------------------------------*/ |
| 80 | /** |
| 81 | * Get Host bridge PCI Address |
| 82 | * |
| 83 | * |
| 84 | * |
| 85 | * @param[in] GnbHandle Socket ID |
| 86 | * @param[in] StdHeader Standard configuration header |
| 87 | * @retval PCI address of GNB for a given socket/silicon. |
| 88 | */ |
| 89 | |
| 90 | PCI_ADDR |
| 91 | GnbFmGetPciAddress ( |
| 92 | IN GNB_HANDLE *GnbHandle, |
| 93 | IN AMD_CONFIG_PARAMS *StdHeader |
| 94 | ) |
| 95 | { |
| 96 | PCI_ADDR GnbPciAddress; |
| 97 | UINT8 NodeId; |
| 98 | UINT8 Register; |
| 99 | UINT32 Value; |
| 100 | GnbPciAddress.AddressValue = ILLEGAL_SBDFO; |
| 101 | NodeId = GnbGetNodeId (GnbHandle); |
| 102 | for (Register = 0xE0; Register <= 0xEC; Register = Register + 4) { |
| 103 | GnbLibPciRead (MAKE_SBDFO (0, 0, 24 + NodeId, 1, Register), AccessWidth32, &Value, StdHeader); |
| 104 | if (((Value >> 4) & 0x7) == NodeId) { |
| 105 | GnbPciAddress.AddressValue = MAKE_SBDFO (0, (Value >> 16) & 0xff, 0, 0, 0); |
| 106 | break; |
| 107 | } |
| 108 | } |
| 109 | ASSERT (GnbPciAddress.AddressValue != ILLEGAL_SBDFO); |
| 110 | return GnbPciAddress; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | /*----------------------------------------------------------------------------------------*/ |
| 115 | /** |
| 116 | * Get bus range decoded by GNB |
| 117 | * |
| 118 | * Final bus allocation can not be assumed until AmdInitMid |
| 119 | * |
| 120 | * @param[in] GnbHandle GNB handle |
| 121 | * @param[out] StartBusNumber Beggining of the Bus Range |
| 122 | * @param[out] EndBusNumber End of the Bus Range |
| 123 | * @param[in] StdHeader Standard configuration header |
| 124 | * @retval Satus |
| 125 | */ |
| 126 | AGESA_STATUS |
| 127 | GnbFmGetBusDecodeRange ( |
| 128 | IN GNB_HANDLE *GnbHandle, |
| 129 | OUT UINT8 *StartBusNumber, |
| 130 | OUT UINT8 *EndBusNumber, |
| 131 | IN AMD_CONFIG_PARAMS *StdHeader |
| 132 | ) |
| 133 | { |
| 134 | UINT8 NodeId; |
| 135 | UINT8 Register; |
| 136 | UINT32 Value; |
| 137 | AGESA_STATUS Status; |
| 138 | Status = AGESA_ERROR; |
| 139 | NodeId = GnbGetNodeId (GnbHandle); |
| 140 | for (Register = 0xE0; Register <= 0xEC; Register = Register + 4) { |
| 141 | GnbLibPciRead (MAKE_SBDFO (0, 0, 24 + NodeId, 1, Register), AccessWidth32, &Value, StdHeader); |
| 142 | if (((Value >> 4) & 0x7) == NodeId) { |
| 143 | *StartBusNumber = (UINT8) ((Value >> 16) & 0xff); |
| 144 | *EndBusNumber = (UINT8) ((Value >> 24) & 0xff); |
| 145 | Status = AGESA_SUCCESS; |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | return Status; |
| 150 | } |
| 151 | |
| 152 | /*----------------------------------------------------------------------------------------*/ |
| 153 | /** |
| 154 | * Get link to which GNB connected to |
| 155 | * |
| 156 | * |
| 157 | * @param[in] GnbHandle GNB handle |
| 158 | * @param[out] LinkId Link to which GNB connected to |
| 159 | * @param[in] StdHeader Standard configuration header |
| 160 | * @retval Satus |
| 161 | */ |
| 162 | |
| 163 | AGESA_STATUS |
| 164 | GnbFmGetLinkId ( |
| 165 | IN GNB_HANDLE *GnbHandle, |
| 166 | OUT UINT8 *LinkId, |
| 167 | IN AMD_CONFIG_PARAMS *StdHeader |
| 168 | ) |
| 169 | { |
| 170 | UINT32 Value; |
| 171 | ASSERT (GnbHandle->NodeId != 0xFF); |
| 172 | GnbLibPciRead (MAKE_SBDFO (0, 0, 0x18 + GnbHandle->NodeId, 0, 0x1A0), AccessWidth32, &Value, StdHeader); |
| 173 | *LinkId = LibAmdBitScanForward (Value & 0xAAAA) / 2; |
| 174 | ASSERT (*LinkId < 8); |
| 175 | return AGESA_SUCCESS; |
| 176 | } |