zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 1 | /** |
| 2 | * @file |
| 3 | * |
| 4 | * ALIB PSPP ASL library |
| 5 | * |
| 6 | * |
| 7 | * |
| 8 | * @xrefitem bom "File Content Label" "Release Content" |
| 9 | * @e project: AGESA |
| 10 | * @e sub-project: GNB |
| 11 | * @e \$Revision: 65976 $ @e \$Date: 2012-02-27 22:24:12 -0600 (Mon, 27 Feb 2012) $ |
| 12 | * |
| 13 | */ |
| 14 | /* |
| 15 | ***************************************************************************** |
| 16 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 17 | * Copyright (c) 2008 - 2012, Advanced Micro Devices, Inc. |
| 18 | * All rights reserved. |
| 19 | * |
| 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions are met: |
| 22 | * * Redistributions of source code must retain the above copyright |
| 23 | * notice, this list of conditions and the following disclaimer. |
| 24 | * * Redistributions in binary form must reproduce the above copyright |
| 25 | * notice, this list of conditions and the following disclaimer in the |
| 26 | * documentation and/or other materials provided with the distribution. |
| 27 | * * Neither the name of Advanced Micro Devices, Inc. nor the names of |
| 28 | * its contributors may be used to endorse or promote products derived |
| 29 | * from this software without specific prior written permission. |
| 30 | * |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 32 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 33 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 34 | * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY |
| 35 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 36 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 38 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 40 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 41 | * *************************************************************************** |
| 42 | * |
| 43 | */ |
| 44 | |
| 45 | /*----------------------------------------------------------------------------------------*/ |
| 46 | /** |
| 47 | * PCIe Performance Policy |
| 48 | * |
| 49 | * varPsppPolicy - 0 Disabled |
| 50 | * 1 Performance |
| 51 | * 2 Balance Hight |
| 52 | * 3 Balance Low |
| 53 | * 4 Power Saving |
| 54 | */ |
| 55 | Name ( |
| 56 | AD02, |
| 57 | 0x0 |
| 58 | ) |
| 59 | |
| 60 | Alias ( |
| 61 | AD02, |
| 62 | varPsppPolicy |
| 63 | ) |
| 64 | |
| 65 | /*----------------------------------------------------------------------------------------*/ |
| 66 | /** |
| 67 | * GEN2 VID |
| 68 | * |
| 69 | */ |
| 70 | |
| 71 | Name ( |
| 72 | AD03, |
| 73 | 0x0 |
| 74 | ) |
| 75 | |
| 76 | Alias ( |
| 77 | AD03, |
| 78 | varGen2Vid |
| 79 | ) |
| 80 | |
| 81 | /*----------------------------------------------------------------------------------------*/ |
| 82 | /** |
| 83 | * GEN1 VID |
| 84 | * |
| 85 | */ |
| 86 | Name ( |
| 87 | AD04, |
| 88 | 0x0 |
| 89 | ) |
| 90 | |
| 91 | Alias ( |
| 92 | AD04, |
| 93 | varGen1Vid |
| 94 | ) |
| 95 | |
| 96 | /*----------------------------------------------------------------------------------------*/ |
| 97 | /** |
| 98 | * Boot VID |
| 99 | * |
| 100 | */ |
| 101 | |
| 102 | Name ( |
| 103 | AD05, |
| 104 | 0x0 |
| 105 | ) |
| 106 | |
| 107 | Alias ( |
| 108 | AD05, |
| 109 | varBootVid |
| 110 | ) |
| 111 | |
| 112 | /*----------------------------------------------------------------------------------------*/ |
| 113 | /** |
| 114 | * Max Port link speed |
| 115 | * |
| 116 | */ |
| 117 | Name (AD06, Package () {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) |
| 118 | |
| 119 | Alias (AD06, varMaxLinkSpeed) |
| 120 | |
| 121 | |
| 122 | /*----------------------------------------------------------------------------------------*/ |
| 123 | /** |
| 124 | * Max link speed that was changed during runtime (hotplug for instance) |
| 125 | * |
| 126 | */ |
| 127 | |
| 128 | Name (AD08, Package () {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) |
| 129 | |
| 130 | Alias (AD08, varOverrideLinkSpeed) |
| 131 | |
| 132 | /*----------------------------------------------------------------------------------------*/ |
| 133 | /** |
| 134 | * Policy service status |
| 135 | * |
| 136 | * varPsppPolicyService - 0 (Stopped) |
| 137 | * 1 (Started) |
| 138 | */ |
| 139 | |
| 140 | Name (varPsppPolicyService, 0x0 ) |
| 141 | |
| 142 | /*----------------------------------------------------------------------------------------*/ |
| 143 | /** |
| 144 | * AC DC state |
| 145 | * |
| 146 | * varPsppAcDcState - 0 (AC) |
| 147 | * 1 (DC) |
| 148 | */ |
| 149 | |
| 150 | Name (varPsppAcDcState, 0x0) |
| 151 | Name (varPsppAcDcOverride, 0x1) |
| 152 | |
| 153 | /*----------------------------------------------------------------------------------------*/ |
| 154 | /** |
| 155 | * Client ID array |
| 156 | * |
| 157 | */ |
| 158 | |
| 159 | Name (varPsppClientIdArray, |
| 160 | Package () {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000} |
| 161 | ) |
| 162 | |
| 163 | Name (varDefaultPsppClientIdArray, |
| 164 | Package () {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000} |
| 165 | ) |
| 166 | /*----------------------------------------------------------------------------------------*/ |
| 167 | /** |
| 168 | * LInk speed requested by device driver |
| 169 | * |
| 170 | */ |
| 171 | |
| 172 | Name (varRequestedLinkSpeed, Package () {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) |
| 173 | |
| 174 | /*----------------------------------------------------------------------------------------*/ |
| 175 | /** |
| 176 | * Current link speed |
| 177 | * |
| 178 | */ |
| 179 | Name (AD09, Package () {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }) |
| 180 | Alias (AD09, varCurrentLinkSpeed) |
| 181 | /*----------------------------------------------------------------------------------------*/ |
| 182 | /** |
| 183 | * Template link speed |
| 184 | * |
| 185 | */ |
| 186 | Name ( |
| 187 | varGen1LinkSpeedTemplate, |
| 188 | Package () { |
| 189 | DEF_LINK_SPEED_GEN1, |
| 190 | DEF_LINK_SPEED_GEN1, |
| 191 | DEF_LINK_SPEED_GEN1, |
| 192 | DEF_LINK_SPEED_GEN1, |
| 193 | DEF_LINK_SPEED_GEN1, |
| 194 | DEF_LINK_SPEED_GEN1, |
| 195 | DEF_LINK_SPEED_GEN1, |
| 196 | DEF_LINK_SPEED_GEN1 |
| 197 | }) |
| 198 | |
| 199 | /*----------------------------------------------------------------------------------------*/ |
| 200 | /** |
| 201 | * Template link speed |
| 202 | * |
| 203 | */ |
| 204 | Name (varLowVoltageRequest, Package () {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }) |
| 205 | |
| 206 | /*----------------------------------------------------------------------------------------*/ |
| 207 | /** |
| 208 | * Global varuable |
| 209 | * |
| 210 | */ |
| 211 | Name (varPortIndex, 0) |
| 212 | |
| 213 | /*----------------------------------------------------------------------------------------*/ |
| 214 | /** |
| 215 | * Sclk VID that was changed during runtime |
| 216 | * |
| 217 | */ |
| 218 | |
| 219 | Name (AD10, Package () {0x00, 0x00, 0x00, 0x00}) |
| 220 | |
| 221 | Alias (AD10, varSclkVid) |
| 222 | |
| 223 | /*----------------------------------------------------------------------------------------*/ |
| 224 | /** |
| 225 | * Report AC/DC state |
| 226 | * |
| 227 | * Arg0 - Data Buffer |
| 228 | */ |
| 229 | Method (procPsppReportAcDsState, 1, Serialized) { |
| 230 | Store ("PsppReportAcDsState Enter", Debug) |
| 231 | |
| 232 | Store (DeRefOf (Index (Arg0, 0x2)), varArgAcDcStateLocal1) |
| 233 | Store (Concatenate (" AC/DC state: ", ToHexString (varArgAcDcStateLocal1), varStringBuffer), Debug) |
| 234 | |
| 235 | Store (procPsppGetAcDcState(), varCurrentAcDcStateLocal0) |
| 236 | Store (varArgAcDcStateLocal1, varPsppAcDcState) |
| 237 | |
| 238 | Or (ShiftLeft (1, DEF_SCARTCH_PSPP_ACDC_OFFSET), ShiftLeft (1, DEF_SCARTCH_PSPP_ACDC_OVR_OFFSET), Local2) |
| 239 | Or (ShiftLeft (varPsppAcDcState, DEF_SCARTCH_PSPP_ACDC_OFFSET), ShiftLeft (varPsppAcDcOverride, DEF_SCARTCH_PSPP_ACDC_OVR_OFFSET), Local3) |
| 240 | procIndirectRegisterRMW (0x0, 0x60, 0xF4, Not (Local2), And (Local2, Local3)) |
| 241 | |
| 242 | |
| 243 | if (LEqual (varArgAcDcStateLocal1, varCurrentAcDcStateLocal0)) { |
| 244 | Store (" No action. [AC/DC state not changed]", Debug) |
| 245 | Store ("PsppReportAcDsState Exit", Debug) |
| 246 | return (0) |
| 247 | } |
| 248 | |
| 249 | // Disable both APM (boost) and PDM flow on DC event enable it on AC. |
| 250 | procApmPdmActivate(varPsppAcDcState) |
| 251 | |
| 252 | // Set DPM state for Power Saving, due to this policy will not attend ApplyPsppState service. |
| 253 | if (LEqual (varPsppPolicy, DEF_PSPP_POLICY_POWERSAVING)) { |
| 254 | procNbLclkDpmActivate(DEF_LINK_SPEED_GEN1) |
| 255 | #ifdef ALTVDDNB_SUPPORT |
| 256 | procNbAltVddNb (DEF_LINK_SPEED_GEN1) |
| 257 | #endif |
| 258 | } |
| 259 | if (LOr (LLessEqual (varPsppPolicy, DEF_PSPP_POLICY_PERFORMANCE), LGreaterEqual (varPsppPolicy, DEF_PSPP_POLICY_POWERSAVING))) { |
| 260 | Store (" No action. [Policy type]", Debug) |
| 261 | Store ("PsppReportAcDsState Exit", Debug) |
| 262 | return (0) |
| 263 | } |
| 264 | if (LEqual (varPsppPolicyService, DEF_PSPP_POLICY_STOP)) { |
| 265 | Store (" No action. [Policy not started]", Debug) |
| 266 | Store ("PsppReportAcDsState Exit", Debug) |
| 267 | return (0) |
| 268 | } |
| 269 | procApplyPsppState () |
| 270 | Store ("PsppReportAcDsState Exit", Debug) |
| 271 | return (0) |
| 272 | } |
| 273 | |
| 274 | /*----------------------------------------------------------------------------------------*/ |
| 275 | /** |
| 276 | * PCIe Performance Request |
| 277 | * |
| 278 | * Arg0 - Data Buffer |
| 279 | */ |
| 280 | Method (procPsppPerformanceRequest, 1, NotSerialized) { |
| 281 | Store (procPsppProcessPerformanceRequest (Arg0), Local7) |
| 282 | Store (DeRefOf (Index (Local7, 2)), varReturnStatusLocal0) |
| 283 | if (LNotEqual (varReturnStatusLocal0, 2)) { |
| 284 | return (Local7) |
| 285 | } |
| 286 | procApplyPsppState () |
| 287 | return (Local7) |
| 288 | } |
| 289 | /*----------------------------------------------------------------------------------------*/ |
| 290 | /** |
| 291 | * PCIe Performance Request |
| 292 | * |
| 293 | * Arg0 - Data Buffer |
| 294 | */ |
| 295 | Method (procPsppProcessPerformanceRequest, 1, NotSerialized) { |
| 296 | Store ("PsppProcessPerformanceRequest Enter", Debug) |
| 297 | Name (varClientBus, 0) |
| 298 | Store (0, varPortIndex) |
| 299 | Store (Buffer (10) {}, Local7) |
| 300 | CreateWordField (Local7, 0x0, varReturnBufferLength) |
| 301 | Store (3, varReturnBufferLength) |
| 302 | CreateByteField (Local7, 0x2, varReturnStatus) |
| 303 | Store (1, varReturnStatus) |
| 304 | |
| 305 | if (LOr (LLessEqual (varPsppPolicy, DEF_PSPP_POLICY_PERFORMANCE), LGreaterEqual (varPsppPolicy, DEF_PSPP_POLICY_POWERSAVING))) { |
| 306 | Store (" No action. [Policy type]", Debug) |
| 307 | Store ("PsppPerformanceRequest Exit", Debug) |
| 308 | return (Local7) |
| 309 | } |
| 310 | if (LEqual (varPsppPolicyService, DEF_PSPP_POLICY_STOP)) { |
| 311 | Store (" No action. [Policy not started]", Debug) |
| 312 | Store ("PsppPerformanceRequest Exit", Debug) |
| 313 | return (Local7) |
| 314 | } |
| 315 | CreateWordField (Arg0, 0x2, varClientId) |
| 316 | CreateWordField (Arg0, 0x4, varValidFlag) |
| 317 | CreateWordField (Arg0, 0x6, varFlag) |
| 318 | CreateByteField (Arg0, 0x8, varRequestType) |
| 319 | CreateByteField (Arg0, 0x9, varRequestData) |
| 320 | |
| 321 | Store (Concatenate (" Client ID : ", ToHexString (varClientId), varStringBuffer), Debug) |
| 322 | Store (Concatenate (" Valid Flags : ", ToHexString (varValidFlag), varStringBuffer), Debug) |
| 323 | Store (Concatenate (" Flags : ", ToHexString (varFlag), varStringBuffer), Debug) |
| 324 | Store (Concatenate (" Request Type: ", ToHexString (varRequestType), varStringBuffer), Debug) |
| 325 | Store (Concatenate (" Request Data: ", ToHexString (varRequestData), varStringBuffer), Debug) |
| 326 | |
| 327 | |
| 328 | And (ShiftRight (varClientId, 8), 0xff, varClientBus) |
| 329 | while (LLessEqual (varPortIndex, varMaxPortIndexNumber)) { |
| 330 | if (LEqual (procChecPortAllocated (varPortIndex), DEF_PORT_ALLOCATED)) { |
| 331 | Store (procPciDwordRead (ShiftLeft (Add( varPortIndex, 2), 3), 0x18), Local1) |
| 332 | And (ShiftRight (Local1, 16), 0xff, varSubordinateBusLocal2) //Local2 Port Subordinate Bus number |
| 333 | And (ShiftRight (Local1, 8), 0xff, varSecondaryBusLocal1) //Local1 Port Secondary Bus number |
| 334 | if (LAnd (LGreaterEqual (varClientBus, Local1), LLessEqual(varClientBus, Local2))) { |
| 335 | break |
| 336 | } |
| 337 | } |
| 338 | Increment (varPortIndex) |
| 339 | } |
| 340 | if (LGreater (varPortIndex, varMaxPortIndexNumber)) { |
| 341 | Store ("PsppPerformanceRequest Exit", Debug) |
| 342 | return (Local7) |
| 343 | } |
| 344 | |
| 345 | Store (Concatenate (" Performance request for port index : ", ToHexString (varPortIndex), Local6), Debug) |
| 346 | |
| 347 | if (LEqual (DeRefOf (Index (varPsppClientIdArray, varPortIndex)), 0x0000)) { |
| 348 | Store (varClientId, Index (varPsppClientIdArray, varPortIndex)) |
| 349 | } ElseIf (LNotEqual (DeRefOf (Index (varPsppClientIdArray, varPortIndex)), varClientId)) { |
| 350 | // We already have registered client |
| 351 | Store (" No action. [Unsupported request]", Debug) |
| 352 | Store ("PsppPerformanceRequest Exit", Debug) |
| 353 | return (Local7) |
| 354 | } |
| 355 | Store (0, Index (varLowVoltageRequest, varPortIndex)) |
| 356 | if (LEqual (varRequestData, 0)) { |
| 357 | Store (0x0000, Index (varPsppClientIdArray, varPortIndex)) |
| 358 | } |
| 359 | if (LEqual (varRequestData, 1)) { |
| 360 | Store (1, Index (varLowVoltageRequest, varPortIndex)) |
| 361 | } |
| 362 | if (LEqual (varRequestData, 2)) { |
| 363 | Store (DEF_LINK_SPEED_GEN1, Index (varRequestedLinkSpeed, varPortIndex)) |
| 364 | } |
| 365 | if (LEqual (varRequestData, 3)) { |
| 366 | Store (DEF_LINK_SPEED_GEN2, Index (varRequestedLinkSpeed, varPortIndex)) |
| 367 | } |
| 368 | if (LEqual (And (varValidFlag, varFlag), 0x1)) { |
| 369 | Store (DerefOf (Index (varMaxLinkSpeed, varPortIndex)), Index (varRequestedLinkSpeed, varPortIndex)) |
| 370 | } |
| 371 | Store (2, varReturnStatus) |
| 372 | Store ("PsppProcessPerformanceRequest Exit", Debug) |
| 373 | return (Local7) |
| 374 | } |
| 375 | |
| 376 | /*----------------------------------------------------------------------------------------*/ |
| 377 | /** |
| 378 | * PSPP Start/Stop Management Request |
| 379 | * |
| 380 | * Arg0 - Data Buffer |
| 381 | */ |
| 382 | |
| 383 | Method (procChecPortAllocated, 1, Serialized) { |
| 384 | if (LEqual (DeRefOf (Index (varMaxLinkSpeed, Arg0)), 0)) { |
| 385 | return (DEF_PORT_NOT_ALLOCATED) |
| 386 | } |
| 387 | return (DEF_PORT_ALLOCATED) |
| 388 | } |
| 389 | |
| 390 | /*----------------------------------------------------------------------------------------*/ |
| 391 | /** |
| 392 | * PSPP Start/Stop Management Request |
| 393 | * |
| 394 | * Arg0 - Data Buffer |
| 395 | */ |
| 396 | Method (procPsppControl, 1, Serialized) { |
| 397 | Store ("PsppControl Enter", Debug) |
| 398 | Store (Buffer (256) {}, Local7) |
| 399 | Store (3, Index (Local7, 0x0)) // Return Buffer Length |
| 400 | Store (0, Index (Local7, 0x1)) // Return Buffer Length |
| 401 | Store (0, Index (Local7, 0x2)) // Return Status |
| 402 | |
| 403 | Store (DerefOf (Index (Arg0, 0x2)), varPsppPolicyService) |
| 404 | |
| 405 | Store (procIndirectRegisterRead (0x0, 0x60, 0xF4), varPsppScratchLocal0) |
| 406 | |
| 407 | if (LEqual (varPsppPolicyService, DEF_PSPP_POLICY_START)) { |
| 408 | if (LEqual (And (varPsppScratchLocal0, 1), DEF_PSPP_POLICY_START)) { |
| 409 | // Policy already started |
| 410 | Store (" No action. [Policy already started]", Debug) |
| 411 | Store ("PsppControl Exit", Debug) |
| 412 | return (Local7) |
| 413 | } |
| 414 | Or (varPsppScratchLocal0, DEF_PSPP_POLICY_START, varPsppScratchLocal0) |
| 415 | } |
| 416 | if (LEqual (varPsppPolicyService, DEF_PSPP_POLICY_STOP)) { |
| 417 | if (LEqual (And (varPsppScratchLocal0, 1), DEF_PSPP_POLICY_STOP)) { |
| 418 | // Policy already stopped |
| 419 | Store (" No action. [Policy already stopped]", Debug) |
| 420 | Store ("PsppControl Exit", Debug) |
| 421 | return (Local7) |
| 422 | } |
| 423 | And (varPsppScratchLocal0, Not (DEF_PSPP_POLICY_START), varPsppScratchLocal0) |
| 424 | } |
| 425 | Or (varPsppScratchLocal0, Shiftleft (varPsppPolicy, DEF_SCARTCH_PSPP_POLICY_OFFSET), varPsppScratchLocal0) |
| 426 | procIndirectRegisterWrite (0x0, 0x60, 0xF4, varPsppScratchLocal0) |
| 427 | |
| 428 | procCopyPackage (RefOf (varDefaultPsppClientIdArray), RefOf (varPsppClientIdArray)) |
| 429 | |
| 430 | // Reevaluate APM/PDM state here on S3 resume while staying on DC. |
| 431 | procApmPdmActivate(varPsppAcDcState) |
| 432 | |
| 433 | // Set DPM state for PSPP Power Saving, due to this policy will not attend ApplyPsppState service. |
| 434 | if (LEqual (varPsppPolicy, DEF_PSPP_POLICY_POWERSAVING)) { |
| 435 | procNbLclkDpmActivate(DEF_LINK_SPEED_GEN1) |
| 436 | #ifdef ALTVDDNB_SUPPORT |
| 437 | procNbAltVddNb (DEF_LINK_SPEED_GEN1) |
| 438 | #endif |
| 439 | } |
| 440 | //Reevaluate PCIe speed for all devices base on PSPP state switch to boot up voltage |
| 441 | if (LAnd (LGreater (varPsppPolicy, DEF_PSPP_POLICY_PERFORMANCE), LLess (varPsppPolicy, DEF_PSPP_POLICY_POWERSAVING))) { |
| 442 | // Load default speed capability state |
| 443 | if (LEqual (varPsppPolicy, DEF_PSPP_POLICY_BALANCEHIGH)) { |
| 444 | procCopyPackage (RefOf (varMaxLinkSpeed), RefOf (varCurrentLinkSpeed)) |
| 445 | Store (0, varPortIndex) |
| 446 | while (LLessEqual (varPortIndex, varMaxPortIndexNumber)) { |
| 447 | if (LNotEqual (DeRefOf (Index (varOverrideLinkSpeed, varPortIndex)), 0)) { |
| 448 | Store (DeRefOf (Index (varOverrideLinkSpeed, varPortIndex)), Index (varCurrentLinkSpeed, varPortIndex)) |
| 449 | } |
| 450 | Increment (varPortIndex) |
| 451 | } |
| 452 | } else { |
| 453 | procCopyPackage (RefOf (varGen1LinkSpeedTemplate), RefOf (varCurrentLinkSpeed)) |
| 454 | #ifdef SBLINK_BALANCE_LOW_GEN2_SUPPORT |
| 455 | Store (DeRefOf (Index (varMaxLinkSpeed, DEF_SB_PORT_INDEX)),Index (varCurrentLinkSpeed, DEF_SB_PORT_INDEX)) |
| 456 | //Store (DEF_LINK_SPEED_GEN2, Index (varCurrentLinkSpeed, DEF_SB_PORT_INDEX)) |
| 457 | #endif |
| 458 | |
| 459 | } |
| 460 | procApplyPsppState () |
| 461 | } |
| 462 | Store ("PsppControl Exit", Debug) |
| 463 | return (Local7) |
| 464 | } |
| 465 | |
| 466 | Name (varNewLinkSpeed, Package () {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) |
| 467 | |
| 468 | /*----------------------------------------------------------------------------------------*/ |
| 469 | /** |
| 470 | * Evaluate PCIe speed on all links according to PSPP state and client requests |
| 471 | * |
| 472 | * |
| 473 | * |
| 474 | */ |
| 475 | Method (procApplyPsppState, 0, Serialized) { |
| 476 | Store ("ApplyPsppState Enter", Debug) |
| 477 | Store (0, varPortIndex) |
| 478 | |
| 479 | procCopyPackage (RefOf (varGen1LinkSpeedTemplate), RefOf (varNewLinkSpeed)) |
| 480 | while (LLessEqual (varPortIndex, varMaxPortIndexNumber)) { |
| 481 | if (LEqual (procChecPortAllocated(varPortIndex), DEF_PORT_ALLOCATED)) { |
| 482 | Store (procGetPortRequestedCapability (varPortIndex), Index (varNewLinkSpeed, varPortIndex)) |
| 483 | } |
| 484 | Increment (varPortIndex) |
| 485 | } |
| 486 | if (LNotEqual(Match (varLowVoltageRequest, MEQ, 0x01, MTR, 0, 0), ONES)) { |
| 487 | procCopyPackage (RefOf (varGen1LinkSpeedTemplate), RefOf (varNewLinkSpeed)) |
| 488 | } |
| 489 | if (LNotEqual(Match (varNewLinkSpeed, MEQ, DEF_LINK_SPEED_GEN2, MTR, 0, 0), ONES)) { |
| 490 | // Set GEN2 voltage |
| 491 | Store ("Set GEN2 VID", Debug) |
| 492 | #ifdef ALTVDDNB_SUPPORT |
| 493 | procNbAltVddNb (DEF_LINK_SPEED_GEN2) |
| 494 | #endif |
| 495 | procPcieSetVoltage (DEF_LINK_SPEED_GEN2, 1) |
| 496 | // procPcieAdjustPll (DEF_LINK_SPEED_GEN2) |
| 497 | procNbLclkDpmActivate(DEF_LINK_SPEED_GEN2) |
| 498 | } |
| 499 | Store (0, varPortIndex) |
| 500 | while (LLessEqual (varPortIndex, varMaxPortIndexNumber)) { |
| 501 | if (LEqual (procChecPortAllocated(varPortIndex), DEF_PORT_NOT_ALLOCATED)) { |
| 502 | Increment (varPortIndex) |
| 503 | continue |
| 504 | } |
| 505 | Store (DerefOf (Index (varCurrentLinkSpeed, varPortIndex)), varCurrentLinkSpeedLocal0) |
| 506 | Store (DerefOf (Index (varNewLinkSpeed, varPortIndex)), varNewLinkSpeedLocal2) |
| 507 | if (LEqual (varCurrentLinkSpeedLocal0, varNewLinkSpeedLocal2)) { |
| 508 | Increment (varPortIndex) |
| 509 | continue |
| 510 | } |
| 511 | Store (varNewLinkSpeedLocal2, Index (varCurrentLinkSpeed, varPortIndex)) |
| 512 | procSetPortCapabilityAndSpeed (varPortIndex, varNewLinkSpeedLocal2) |
| 513 | Increment (varPortIndex) |
| 514 | } |
| 515 | if (LEqual(Match (varNewLinkSpeed, MEQ, DEF_LINK_SPEED_GEN2, MTR, 0, 0), ONES)) { |
| 516 | // Set GEN1 voltage |
| 517 | Store ("Set GEN1 VID", Debug) |
| 518 | procNbLclkDpmActivate(DEF_LINK_SPEED_GEN1) |
| 519 | // procPcieAdjustPll (DEF_LINK_SPEED_GEN1) |
| 520 | procPcieSetVoltage (DEF_LINK_SPEED_GEN1, 0) |
| 521 | #ifdef ALTVDDNB_SUPPORT |
| 522 | procNbAltVddNb (DEF_LINK_SPEED_GEN1) |
| 523 | #endif |
| 524 | } |
| 525 | #ifdef PHY_SPEED_REPORT_SUPPORT |
| 526 | procReportPhySpeedCap () |
| 527 | #endif |
| 528 | Store ("ApplyPsppState Exit", Debug) |
| 529 | } |
| 530 | /*----------------------------------------------------------------------------------------*/ |
| 531 | /** |
| 532 | * Read PCI config register |
| 533 | * |
| 534 | * Arg0 - Port Index |
| 535 | * |
| 536 | */ |
| 537 | Method (procGetPortRequestedCapability, 1) { |
| 538 | Store (DEF_LINK_SPEED_GEN2, varCurrentSpeedLocal0) |
| 539 | Store (procPsppGetAcDcState(), varAcDcStateLocal1) |
| 540 | if (LEqual (DerefOf (Index (varPsppClientIdArray, Arg0)), 0x0000)) { |
| 541 | if (LOr (LEqual (varAcDcStateLocal1, DEF_PSPP_STATE_DC), LEqual (varPsppPolicy, DEF_PSPP_POLICY_BALANCELOW))) { |
| 542 | // Default policy cap to GEN1 |
| 543 | Store (DEF_LINK_SPEED_GEN1, varCurrentSpeedLocal0) |
| 544 | } |
| 545 | #ifdef SBLINK_BALANCE_LOW_GEN2_SUPPORT |
| 546 | if (LAnd (LEqual (varAcDcStateLocal1, DEF_PSPP_STATE_AC), LEqual (varPsppPolicy, DEF_PSPP_POLICY_BALANCELOW))) { |
| 547 | if (LEqual (Arg0, DEF_SB_PORT_INDEX)) { |
| 548 | Store (DEF_LINK_SPEED_GEN2, varCurrentSpeedLocal0) |
| 549 | } |
| 550 | } |
| 551 | #endif |
| 552 | if (LNotEqual (DerefOf (Index (varOverrideLinkSpeed, Arg0)), 0)) { |
| 553 | Store (DerefOf (Index (varOverrideLinkSpeed, Arg0)), varCurrentSpeedLocal0) |
| 554 | } |
| 555 | } else { |
| 556 | Store (DerefOf (Index (varRequestedLinkSpeed, Arg0)), varCurrentSpeedLocal0) |
| 557 | } |
| 558 | Store (DerefOf (Index (varMaxLinkSpeed, varPortIndex)),varMaxLinkSpeedLocal2) |
| 559 | if (LLess (varMaxLinkSpeedLocal2, varCurrentSpeedLocal0)) { |
| 560 | Store (varMaxLinkSpeedLocal2, varCurrentSpeedLocal0) |
| 561 | } |
| 562 | |
| 563 | |
| 564 | return (varCurrentSpeedLocal0) |
| 565 | } |
| 566 | |
| 567 | /*----------------------------------------------------------------------------------------*/ |
| 568 | /** |
| 569 | * Set capability and speed |
| 570 | * |
| 571 | * Arg0 - Port Index |
| 572 | * Arg1 - Link speed |
| 573 | */ |
| 574 | Method (procSetPortCapabilityAndSpeed, 2, NotSerialized) { |
| 575 | Store ("SetPortCapabilityAndSpeed Enter", Debug) |
| 576 | Store (Concatenate (" Port Index : ", ToHexString (Arg0), varStringBuffer), Debug) |
| 577 | Store (Concatenate (" Speed : ", ToHexString (Arg1), varStringBuffer), Debug) |
| 578 | |
| 579 | //UnHide UMI port |
| 580 | if (LEqual (Arg0, 6)) { |
| 581 | procIndirectRegisterRMW (0x0, 0x60, 0x80, Not (0x40), 0x40); |
| 582 | } |
| 583 | |
| 584 | procPcieSetLinkSpeed (Arg0, Arg1) |
| 585 | |
| 586 | // Programming for LcInitSpdChgWithCsrEn |
| 587 | if (LNotEqual (DeRefOf (Index (varPsppClientIdArray, Arg0)), 0x0000)) { |
| 588 | // Registered port, LcInitSpdChgWithCsrEn = 0. |
| 589 | procPciePortIndirectRegisterRMW (Arg0, 0xA1, Not (0x00001000), 0x0) |
| 590 | } else { |
| 591 | procPciePortIndirectRegisterRMW (Arg0, 0xA1, Not (0x00001000), 0x00001000) |
| 592 | } |
| 593 | |
| 594 | // Determine port PCI address and check port present |
| 595 | Store (ShiftLeft (Add( Arg0, 2), 3), varPortBdfLocal1) |
| 596 | And (procPciePortIndirectRegisterRead (Arg0, 0xA5), 0x3f, varPortPresentLocal3) |
| 597 | procPciePortIndirectRegisterWrite (Arg0, 0x1, varPortPresentLocal3) |
| 598 | if (LGreaterEqual (varPortPresentLocal3, 0x10)) { |
| 599 | procDisableAndSaveAspm (Arg0) |
| 600 | Store (1, Local2) |
| 601 | while (Local2) { |
| 602 | //retrain port |
| 603 | procPciDwordRMW (varPortBdfLocal1, 0x68, Not (0x00000000), 0x20) |
| 604 | Sleep (30) |
| 605 | while (And (procPciDwordRead (varPortBdfLocal1, 0x68), 0x08000000)) { |
| 606 | Sleep (10) |
| 607 | } |
| 608 | Store (0, Local2) |
| 609 | if (LEqual (Arg1, DEF_LINK_SPEED_GEN1)) { |
| 610 | //Store (procPciePortIndirectRegisterRead (Arg0, 0xA4), varLcCurrentLinkSpeedLocal4) |
| 611 | if (LNotEqual (procPciePortGetCurrentLinkSpeed (Arg0), DEF_LINK_SPEED_GEN1)) { |
| 612 | Store (1, Local2) |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | procRestoreAspm (Arg0) |
| 617 | } else { |
| 618 | Store (" Device not present. Set capability and speed only", Debug) |
| 619 | } |
| 620 | //Hide UMI port |
| 621 | if (LEqual (Arg0, 6)) { |
| 622 | procIndirectRegisterRMW (0x0, 0x60, 0x80, Not (0x40), 0x00); |
| 623 | } |
| 624 | Store ("SetPortCapabilityAndSpeed Exit", Debug) |
| 625 | } |
| 626 | |
| 627 | Name (varPcieLinkControlArray, Package () {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}) |
| 628 | Name (varPcieLinkControlOffset, 0) |
| 629 | Name (varPcieLinkControlData, 0) |
| 630 | Name (varPcieRcControlData, 0) |
| 631 | |
| 632 | /*----------------------------------------------------------------------------------------*/ |
| 633 | /** |
| 634 | * Disable and save ASPM state |
| 635 | * |
| 636 | * Arg0 - Port Index |
| 637 | */ |
| 638 | Method (procDisableAndSaveAspm, 1, Serialized) { |
| 639 | Store (0, varPcieLinkControlOffset) |
| 640 | Store (0, varPcieLinkControlData) |
| 641 | |
| 642 | Store (ShiftLeft (Add( Arg0, 2), 3), varPortBdfLocal1) |
| 643 | if (LEqual (Arg0, 6)) { |
| 644 | Store (" Disable SB ASPM", Debug) |
| 645 | Store (procPcieSbAspmControl (0, 0), Index (varPcieLinkControlArray, 0)) |
| 646 | Store (Concatenate (" PcieLinkControl Data : ", ToHexString (DerefOf(Index (varPcieLinkControlArray, 0))), varStringBuffer), Debug) |
| 647 | procPcieSbAspmControl (0, 1) |
| 648 | return (0) |
| 649 | } |
| 650 | |
| 651 | Store (procPciDwordRead (varPortBdfLocal1, 0x18), varTempLocal3) |
| 652 | Store (And (ShiftRight (varTempLocal3, 8), 0xFF), varTempLocal3) |
| 653 | |
| 654 | Store (Concatenate (" Disable EP ASPM on Secondary Bus : ", ToHexString (varTempLocal3), varStringBuffer), Debug) |
| 655 | |
| 656 | Store (ShiftLeft (varTempLocal3, 8), varEndpointBdfLocal2) |
| 657 | Store (procPciDwordRead (varEndpointBdfLocal2, 0xC), varTempLocal3) |
| 658 | Store (And (ShiftRight (varTempLocal3, 16), 0xFF), varTempLocal3) |
| 659 | |
| 660 | Store (Concatenate (" EP Header type : ", ToHexString (varTempLocal3), varStringBuffer), Debug) |
| 661 | |
| 662 | if (LNotEqual (And (varTempLocal3, 0x80), 0)) { |
| 663 | Store (0x7, varMaxFunctionLocal0) |
| 664 | } else { |
| 665 | Store (0x0, varMaxFunctionLocal0) |
| 666 | } |
| 667 | Store (0, varFunctionLocal4) |
| 668 | while (LLessEqual (varFunctionLocal4, varMaxFunctionLocal0)) { |
| 669 | //Find PcieLinkControl register offset = PcieCapPtr + 0x10 |
| 670 | Store (procFindPciCapability (Add (varEndpointBdfLocal2, varFunctionLocal4), 0x10), varPcieLinkControlOffset) |
| 671 | if (LEqual (varPcieLinkControlOffset, 0)) { |
| 672 | Increment (varFunctionLocal4) |
| 673 | continue |
| 674 | } |
| 675 | Add (varPcieLinkControlOffset, 0x10, varPcieLinkControlOffset) |
| 676 | |
| 677 | Store (Concatenate (" Function number of Secondary Bus : ", ToHexString (varFunctionLocal4), varStringBuffer), Debug) |
| 678 | Store (Concatenate (" PcieLinkControl register offset : ", ToHexString (varPcieLinkControlOffset), varStringBuffer), Debug) |
| 679 | // Save ASPM on EP |
| 680 | Store (procPciDwordRead (Add (varEndpointBdfLocal2, varFunctionLocal4) , varPcieLinkControlOffset), varPcieLinkControlData) |
| 681 | Store (And (varPcieLinkControlData, 0x3), Index (varPcieLinkControlArray, varFunctionLocal4)) |
| 682 | |
| 683 | Store (Concatenate (" PcieLinkControl Data : ", ToHexString (varPcieLinkControlData), varStringBuffer), Debug) |
| 684 | |
| 685 | procPciDwordRMW (Add (varEndpointBdfLocal2, varFunctionLocal4), varPcieLinkControlOffset, Not (0x00000003), 0x00) |
| 686 | Store ("Disable ASPM on EP Complete!!", Debug) |
| 687 | Increment (varFunctionLocal4) |
| 688 | } |
| 689 | //Disable ASPM on RC |
| 690 | Store (procPciDwordRead (varPortBdfLocal1, 0x68), varPcieRcControlData) |
| 691 | procPciDwordRMW (varPortBdfLocal1, 0x68, Not (0x00000003), 0x00) |
| 692 | } |
| 693 | /*----------------------------------------------------------------------------------------*/ |
| 694 | /** |
| 695 | * Restore ASPM |
| 696 | * |
| 697 | * Arg0 - Port Index |
| 698 | */ |
| 699 | Method (procRestoreAspm, 1, Serialized) { |
| 700 | |
| 701 | Store (0, varPcieLinkControlOffset) |
| 702 | Store (0, varPcieLinkControlData) |
| 703 | |
| 704 | |
| 705 | // Restore SB ASPM |
| 706 | if (LEqual (Arg0, 6)) { |
| 707 | Store (" Restore SB ASPM", Debug) |
| 708 | Store (Concatenate (" PcieLinkControl Data : ", ToHexString (DerefOf(Index (varPcieLinkControlArray, 0))), varStringBuffer), Debug) |
| 709 | procPcieSbAspmControl (DerefOf(Index (varPcieLinkControlArray, 0)), 1) |
| 710 | return (0) |
| 711 | } |
| 712 | Store (ShiftLeft (Add( Arg0, 2), 3), varPortBdfLocal1) |
| 713 | // Restore EP ASPM |
| 714 | Store (procPciDwordRead (varPortBdfLocal1, 0x18), varTempLocal3) |
| 715 | Store (And (ShiftRight (varTempLocal3, 8), 0xFF), varTempLocal3) |
| 716 | // Restore ASPM on RC |
| 717 | procPciDwordRMW (varPortBdfLocal1, 0x68, Not (0x00000003), And (varPcieRcControlData, 0x3)) |
| 718 | |
| 719 | Store (Concatenate (" Disable EP ASPM on SecondaryBus : ", ToHexString (varTempLocal3), varStringBuffer), Debug) |
| 720 | |
| 721 | Store (ShiftLeft (varTempLocal3, 8), varEndpointBdfLocal2) |
| 722 | Store (procPciDwordRead (varEndpointBdfLocal2, 0xC), varTempLocal3) |
| 723 | Store (And (ShiftRight (varTempLocal3, 16), 0xFF), varTempLocal3) |
| 724 | |
| 725 | Store (Concatenate (" EP Header type : ", ToHexString (varTempLocal3), varStringBuffer), Debug) |
| 726 | |
| 727 | if (LNotEqual (And (varTempLocal3, 0x80), 0)) { |
| 728 | Store (0x7, varMaxFunctionLocal0) |
| 729 | } else { |
| 730 | Store (0x0, varMaxFunctionLocal0) |
| 731 | } |
| 732 | Store (0, varFunctionLocal4) |
| 733 | while (LLessEqual (varFunctionLocal4, varMaxFunctionLocal0)) { |
| 734 | //Find PcieLinkControl register offset = PcieCapPtr + 0x10 |
| 735 | Store (procFindPciCapability (Add (varEndpointBdfLocal2, varFunctionLocal4), 0x10), varPcieLinkControlOffset) |
| 736 | if (LEqual (varPcieLinkControlOffset, 0)) { |
| 737 | Increment (varFunctionLocal4) |
| 738 | continue |
| 739 | } |
| 740 | Add (varPcieLinkControlOffset, 0x10, varPcieLinkControlOffset) |
| 741 | |
| 742 | Store (Concatenate (" Restore Function number of SecondaryBus : ", ToHexString (varFunctionLocal4), varStringBuffer), Debug) |
| 743 | Store (Concatenate (" Restore PcieLinkControl register offset : ", ToHexString (varPcieLinkControlOffset), varStringBuffer), Debug) |
| 744 | Store (Concatenate (" PcieLinkControl Data : ", ToHexString (DerefOf (Index (varPcieLinkControlArray, varFunctionLocal4))), varStringBuffer), Debug) |
| 745 | |
| 746 | procPciDwordWrite (Add (varEndpointBdfLocal2, varFunctionLocal4), varPcieLinkControlOffset, DerefOf (Index (varPcieLinkControlArray, varFunctionLocal4))) |
| 747 | Increment (varFunctionLocal4) |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | /*----------------------------------------------------------------------------------------*/ |
| 752 | /** |
| 753 | * Request VID |
| 754 | * |
| 755 | * Arg0 - Port Index |
| 756 | * Arg1 - PCIe speed |
| 757 | */ |
| 758 | |
| 759 | Method (procPcieSetLinkSpeed, 2) { |
| 760 | Store (ShiftLeft (Add( Arg0, 2), 3), Local0) |
| 761 | if (LEqual (Arg1, DEF_LINK_SPEED_GEN1)) { |
| 762 | procPciDwordRMW (Local0, 0x88, Not (0x0000002f), 0x21) |
| 763 | procPciePortIndirectRegisterRMW (Arg0, 0xA4, Not (0x20000001), 0x0) |
| 764 | } else { |
| 765 | procPciePortIndirectRegisterRMW (Arg0, 0xA4, Not (0x20000001), 0x20000001) |
| 766 | procPciDwordRMW (Local0, 0x88, Not (0x0000002f), 0x2) |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | /*----------------------------------------------------------------------------------------*/ |
| 771 | /** |
| 772 | * Read PCIe port indirect register |
| 773 | * |
| 774 | * Arg0 - Ref Source Pckage |
| 775 | * Arg1 - Ref to Destination Package |
| 776 | * |
| 777 | */ |
| 778 | Method (procCopyPackage, 2, NotSerialized) { |
| 779 | |
| 780 | Store (SizeOf (Arg0), Local1) |
| 781 | Store (0, Local0) |
| 782 | While (LLess (Local0, Local1)) { |
| 783 | Store (DerefOf(Index(DerefOf (Arg0), Local0)), Index(DerefOf (Arg1), Local0)) |
| 784 | Increment (Local0) |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | /*----------------------------------------------------------------------------------------*/ |
| 789 | /** |
| 790 | * Read PCIe port indirect register |
| 791 | * |
| 792 | * Arg0 - Ref Source Pckage |
| 793 | * Arg1 - Ref to Destination Package |
| 794 | * |
| 795 | */ |
| 796 | Method (procPsppGetAcDcState, 0 , NotSerialized) { |
| 797 | Return (And (varPsppAcDcState, varPsppAcDcOverride)) |
| 798 | } |