Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 1 | /* $NoKeywords:$ */ |
| 2 | /** |
| 3 | * @file |
| 4 | * |
| 5 | * Service procedure to calculate PCIe topology segment maximum exit latency |
| 6 | * |
| 7 | * |
| 8 | * |
| 9 | * @xrefitem bom "File Content Label" "Release Content" |
| 10 | * @e project: AGESA |
| 11 | * @e sub-project: GNB |
| 12 | * @e \$Revision: 38298 $ @e \$Date: 2010-09-21 07:15:32 -0700 (Tue, 21 Sep 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 "Gnb.h" |
| 54 | #include "GnbPcie.h" |
| 55 | #include GNB_MODULE_DEFINITIONS (GnbCommonLib) |
| 56 | #include GNB_MODULE_DEFINITIONS (GnbPcieInitLibV1) |
| 57 | #include "Filecode.h" |
| 58 | #define FILECODE PROC_GNB_MODULES_GNBPCIEINITLIBV1_PCIEASPMEXITLATENCY_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 | PCIe_ASPM_LATENCY_INFO *AspmLatencyInfo; |
| 73 | PCI_ADDR DownstreamPort; |
| 74 | UINT8 LinkCount; |
| 75 | } PCIE_EXIT_LATENCY_DATA; |
| 76 | |
| 77 | /*---------------------------------------------------------------------------------------- |
| 78 | * 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 |
| 79 | *---------------------------------------------------------------------------------------- |
| 80 | */ |
| 81 | |
| 82 | SCAN_STATUS |
| 83 | PcieAspmGetMaxExitLatencyCallback ( |
| 84 | IN PCI_ADDR Device, |
| 85 | IN OUT GNB_PCI_SCAN_DATA *ScanData |
| 86 | ); |
| 87 | |
| 88 | /*----------------------------------------------------------------------------------------*/ |
| 89 | /** |
| 90 | * Determine ASPM L-state maximum exit latency for PCIe segment |
| 91 | * |
| 92 | * Scan through all link in segment to determine maxim exit latency requirement by EPs. |
| 93 | * |
| 94 | * @param[in] DownstreamPort PCI address of PCIe port |
| 95 | * @param[out] AspmLatencyInfo Latency info |
| 96 | * @param[in] StdHeader Standard configuration header |
| 97 | * |
| 98 | */ |
| 99 | |
| 100 | VOID |
| 101 | PcieAspmGetMaxExitLatency ( |
| 102 | IN PCI_ADDR DownstreamPort, |
| 103 | OUT PCIe_ASPM_LATENCY_INFO *AspmLatencyInfo, |
| 104 | IN AMD_CONFIG_PARAMS *StdHeader |
| 105 | ) |
| 106 | { |
| 107 | PCIE_EXIT_LATENCY_DATA PcieExitLatencyData; |
| 108 | PcieExitLatencyData.AspmLatencyInfo = AspmLatencyInfo; |
| 109 | PcieExitLatencyData.ScanData.StdHeader = StdHeader; |
| 110 | PcieExitLatencyData.LinkCount = 0; |
| 111 | PcieExitLatencyData.ScanData.GnbScanCallback = PcieAspmGetMaxExitLatencyCallback; |
| 112 | GnbLibPciScan (DownstreamPort, DownstreamPort, &PcieExitLatencyData.ScanData); |
| 113 | } |
| 114 | |
| 115 | /*----------------------------------------------------------------------------------------*/ |
| 116 | /** |
| 117 | * Evaluate device |
| 118 | * |
| 119 | * |
| 120 | * |
| 121 | * @param[in] Device PCI Address |
| 122 | * @param[in,out] ScanData Scan configuration data |
| 123 | * @retval Scan Status of 0 |
| 124 | */ |
| 125 | |
| 126 | SCAN_STATUS |
| 127 | PcieAspmGetMaxExitLatencyCallback ( |
| 128 | IN PCI_ADDR Device, |
| 129 | IN OUT GNB_PCI_SCAN_DATA *ScanData |
| 130 | ) |
| 131 | { |
| 132 | SCAN_STATUS ScanStatus; |
| 133 | PCIE_EXIT_LATENCY_DATA *PcieExitLatencyData; |
| 134 | PCIE_DEVICE_TYPE DeviceType; |
| 135 | UINT32 Value; |
| 136 | UINT8 PcieCapPtr; |
| 137 | UINT8 L1AcceptableLatency; |
| 138 | |
| 139 | PcieExitLatencyData = (PCIE_EXIT_LATENCY_DATA*) ScanData; |
| 140 | ScanStatus = SCAN_SUCCESS; |
| 141 | DeviceType = GnbLibGetPcieDeviceType (Device, ScanData->StdHeader); |
| 142 | IDS_HDT_CONSOLE (GNB_TRACE, " PcieAspmGetMaxExitLatencyCallback for Device = %d:%d:%d\n", |
| 143 | Device.Address.Bus, |
| 144 | Device.Address.Device, |
| 145 | Device.Address.Function |
| 146 | ); |
| 147 | switch (DeviceType) { |
| 148 | case PcieDeviceRootComplex: |
| 149 | case PcieDeviceDownstreamPort: |
| 150 | PcieExitLatencyData->DownstreamPort = Device; |
| 151 | PcieExitLatencyData->LinkCount++; |
| 152 | GnbLibPciScanSecondaryBus (Device, &PcieExitLatencyData->ScanData); |
| 153 | PcieExitLatencyData->LinkCount--; |
| 154 | break; |
| 155 | case PcieDeviceUpstreamPort: |
| 156 | GnbLibPciScanSecondaryBus (Device, &PcieExitLatencyData->ScanData); |
| 157 | break; |
| 158 | case PcieDeviceEndPoint: |
| 159 | case PcieDeviceLegacyEndPoint: |
| 160 | PcieCapPtr = GnbLibFindPciCapability (Device.AddressValue, PCIE_CAP_ID, ScanData->StdHeader); |
| 161 | ASSERT (PcieCapPtr != 0); |
| 162 | GnbLibPciRead ( |
| 163 | Device.AddressValue | (PcieCapPtr + PCIE_LINK_CAP_REGISTER), |
| 164 | AccessWidth32, |
| 165 | &Value, |
| 166 | ScanData->StdHeader |
| 167 | ); |
| 168 | if ((Value & PCIE_ASPM_L1_SUPPORT_CAP) != 0) { |
| 169 | GnbLibPciRead ( |
| 170 | Device.AddressValue | (PcieCapPtr + PCIE_DEVICE_CAP_REGISTER), |
| 171 | AccessWidth32, |
| 172 | &Value, |
| 173 | ScanData->StdHeader |
| 174 | ); |
| 175 | L1AcceptableLatency = (UINT8) (1 << ((Value >> 9) & 0x7)); |
| 176 | if (PcieExitLatencyData->LinkCount > 1) { |
| 177 | L1AcceptableLatency = L1AcceptableLatency + PcieExitLatencyData->LinkCount; |
| 178 | } |
| 179 | if (PcieExitLatencyData->AspmLatencyInfo->MaxL1ExitLatency < L1AcceptableLatency) { |
| 180 | PcieExitLatencyData->AspmLatencyInfo->MaxL1ExitLatency = L1AcceptableLatency; |
| 181 | } |
| 182 | IDS_HDT_CONSOLE (PCIE_MISC, " Device max exit latency L1 - %d us\n", |
| 183 | L1AcceptableLatency |
| 184 | ); |
| 185 | } |
| 186 | break; |
| 187 | default: |
| 188 | break; |
| 189 | } |
| 190 | return SCAN_SUCCESS; |
| 191 | } |
| 192 | |