Angel Pons | c5381e0 | 2020-10-25 12:56:29 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Angel Pons | f239b5a | 2020-10-25 12:58:32 +0100 | [diff] [blame] | 3 | Scope (\_SB.PCI0.MCHC) |
| 4 | { |
Angel Pons | c5381e0 | 2020-10-25 12:56:29 +0100 | [diff] [blame] | 5 | Mutex (CTCM, 1) /* CTDP Switch Mutex (sync level 1) */ |
| 6 | Name (CTCC, 0) /* CTDP Current Selection */ |
| 7 | Name (CTCN, 0) /* CTDP Nominal Select */ |
| 8 | Name (CTCD, 1) /* CTDP Down Select */ |
| 9 | Name (CTCU, 2) /* CTDP Up Select */ |
| 10 | Name (SPL1, 0) /* Saved PL1 value */ |
| 11 | |
Angel Pons | f95b9b4 | 2021-01-20 01:10:48 +0100 | [diff] [blame] | 12 | OperationRegion (MCHB, SystemMemory, CONFIG_FIXED_MCHBAR_MMIO_BASE + 0x5000, 0x1000) |
Angel Pons | c5381e0 | 2020-10-25 12:56:29 +0100 | [diff] [blame] | 13 | Field (MCHB, DWordAcc, Lock, Preserve) |
| 14 | { |
| 15 | Offset (0x930), /* PACKAGE_POWER_SKU */ |
| 16 | CTDN, 15, /* CTDP Nominal PL1 */ |
| 17 | Offset (0x938), /* PACKAGE_POWER_SKU_UNIT */ |
| 18 | PUNI, 4, /* Power Units */ |
| 19 | , 4, |
| 20 | EUNI, 5, /* Energy Units */ |
| 21 | , 3, |
| 22 | TUNI, 4, /* Time Units */ |
| 23 | Offset (0x958), /* PLATFORM_INFO */ |
| 24 | , 40, |
| 25 | LFM_, 8, /* Maximum Efficiency Ratio (LFM) */ |
| 26 | Offset (0x9a0), /* TURBO_POWER_LIMIT1 */ |
| 27 | PL1V, 15, /* Power Limit 1 Value */ |
| 28 | PL1E, 1, /* Power Limit 1 Enable */ |
| 29 | PL1C, 1, /* Power Limit 1 Clamp */ |
| 30 | PL1T, 7, /* Power Limit 1 Time */ |
| 31 | Offset (0x9a4), /* TURBO_POWER_LIMIT2 */ |
| 32 | PL2V, 15, /* Power Limit 2 Value */ |
| 33 | PL2E, 1, /* Power Limit 2 Enable */ |
| 34 | PL2C, 1, /* Power Limit 2 Clamp */ |
| 35 | PL2T, 7, /* Power Limit 2 Time */ |
| 36 | Offset (0xf3c), /* CONFIG_TDP_NOMINAL */ |
| 37 | TARN, 8, /* CTDP Nominal Turbo Activation Ratio */ |
| 38 | Offset (0xf40), /* CONFIG_TDP_LEVEL1 */ |
| 39 | CTDD, 15, /* CTDP Down PL1 */ |
| 40 | , 1, |
| 41 | TARD, 8, /* CTDP Down Turbo Activation Ratio */ |
| 42 | Offset (0xf48), /* MSR_CONFIG_TDP_LEVEL2 */ |
| 43 | CTDU, 15, /* CTDP Up PL1 */ |
| 44 | , 1, |
| 45 | TARU, 8, /* CTDP Up Turbo Activation Ratio */ |
| 46 | Offset (0xf50), /* CONFIG_TDP_CONTROL */ |
| 47 | CTCS, 2, /* CTDP Select */ |
| 48 | Offset (0xf54), /* TURBO_ACTIVATION_RATIO */ |
| 49 | TARS, 8, /* Turbo Activation Ratio Select */ |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Search CPU0 _PSS looking for control = arg0 and then |
| 54 | * return previous P-state entry number for new _PPC |
| 55 | * |
| 56 | * Format of _PSS: |
| 57 | * Name (_PSS, Package () { |
| 58 | * Package (6) { freq, power, tlat, blat, control, status } |
| 59 | * } |
| 60 | */ |
| 61 | External (\_SB.CP00._PSS) |
| 62 | Method (PSSS, 1, NotSerialized) |
| 63 | { |
| 64 | Local0 = 1 /* Start at P1 */ |
| 65 | Local1 = SizeOf (\_SB.CP00._PSS) |
| 66 | |
| 67 | While (Local0 < Local1) { |
| 68 | /* Store _PSS entry Control value to Local2 */ |
| 69 | Local2 = DeRefOf (Index (DeRefOf (Index (\_SB.CP00._PSS, Local0)), 4)) >> 8 |
| 70 | If (Local2 == Arg0) { |
| 71 | Return (Local0 - 1) |
| 72 | } |
| 73 | Local0++ |
| 74 | } |
| 75 | |
| 76 | Return (0) |
| 77 | } |
| 78 | |
| 79 | /* Calculate PL2 based on chip type */ |
| 80 | Method (CPL2, 1, NotSerialized) |
| 81 | { |
Angel Pons | fe91192 | 2020-10-25 23:08:04 +0100 | [diff] [blame] | 82 | #if CONFIG(INTEL_LYNXPOINT_LP) |
| 83 | /* Haswell ULT PL2 = 25W */ |
| 84 | Return (25 * 8) |
| 85 | #else |
| 86 | /* Haswell Mobile PL2 = 1.25 * PL1 */ |
| 87 | Return ((Arg0 * 125) / 100) |
| 88 | #endif |
Angel Pons | c5381e0 | 2020-10-25 12:56:29 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* Set Config TDP Down */ |
| 92 | Method (STND, 0, Serialized) |
| 93 | { |
| 94 | If (Acquire (CTCM, 100)) { |
| 95 | Return (0) |
| 96 | } |
| 97 | If (CTCD == CTCC) { |
| 98 | Release (CTCM) |
| 99 | Return (0) |
| 100 | } |
| 101 | |
| 102 | Debug = "Set TDP Down" |
| 103 | |
| 104 | /* Set CTC */ |
| 105 | CTCS = CTCD |
| 106 | |
| 107 | /* Set TAR */ |
| 108 | TARS = TARD |
| 109 | |
| 110 | /* Set PPC limit and notify OS */ |
| 111 | PPCM = PSSS (TARD) |
| 112 | PPCN () |
| 113 | |
| 114 | /* Set PL2 */ |
| 115 | PL2V = CPL2 (CTDD) |
| 116 | |
| 117 | /* Set PL1 */ |
| 118 | PL1V = CTDD |
| 119 | |
| 120 | /* Store the new TDP Down setting */ |
| 121 | CTCC = CTCD |
| 122 | |
| 123 | Release (CTCM) |
| 124 | Return (1) |
| 125 | } |
| 126 | |
| 127 | /* Set Config TDP Nominal from Down */ |
| 128 | Method (STDN, 0, Serialized) |
| 129 | { |
| 130 | If (Acquire (CTCM, 100)) { |
| 131 | Return (0) |
| 132 | } |
| 133 | If (CTCN == CTCC) { |
| 134 | Release (CTCM) |
| 135 | Return (0) |
| 136 | } |
| 137 | |
| 138 | Debug = "Set TDP Nominal" |
| 139 | |
| 140 | /* Set PL1 */ |
| 141 | PL1V = CTDN |
| 142 | |
| 143 | /* Set PL2 */ |
| 144 | PL2V = CPL2 (CTDN) |
| 145 | |
| 146 | /* Set PPC limit and notify OS */ |
| 147 | PPCM = PSSS (TARN) |
| 148 | PPCN () |
| 149 | |
| 150 | /* Set TAR */ |
| 151 | TARS = TARN |
| 152 | |
| 153 | /* Set CTC */ |
| 154 | CTCS = CTCN |
| 155 | |
| 156 | /* Store the new TDP Nominal setting */ |
| 157 | CTCC = CTCN |
| 158 | |
| 159 | Release (CTCM) |
| 160 | Return (1) |
| 161 | } |
| 162 | |
| 163 | /* Calculate PL1 value based on requested TDP */ |
| 164 | Method (TDPP, 1, NotSerialized) |
| 165 | { |
| 166 | Return (((PUNI - 1) << 2) * Arg0) |
| 167 | } |
| 168 | |
| 169 | /* Enable Controllable TDP to limit PL1 to requested value */ |
| 170 | Method (CTLE, 1, Serialized) |
| 171 | { |
| 172 | If (Acquire (CTCM, 100)) { |
| 173 | Return (0) |
| 174 | } |
| 175 | |
| 176 | Debug = "Enable PL1 Limit" |
| 177 | |
| 178 | /* Set _PPC to LFM */ |
| 179 | Local0 = PSSS (LFM_) |
| 180 | PPCM = Local0 + 1 |
| 181 | \PPCN () |
| 182 | |
| 183 | /* Set TAR to LFM-1 */ |
| 184 | TARS = LFM_ - 1 |
| 185 | |
| 186 | /* Set PL1 to desired value */ |
| 187 | SPL1 = PL1V |
| 188 | PL1V = TDPP (Arg0) |
| 189 | |
| 190 | /* Set PL1 CLAMP bit */ |
| 191 | PL1C = 1 |
| 192 | |
| 193 | Release (CTCM) |
| 194 | Return (1) |
| 195 | } |
| 196 | |
| 197 | /* Disable Controllable TDP */ |
| 198 | Method (CTLD, 0, Serialized) |
| 199 | { |
| 200 | If (Acquire (CTCM, 100)) { |
| 201 | Return (0) |
| 202 | } |
| 203 | |
| 204 | Debug = "Disable PL1 Limit" |
| 205 | |
| 206 | /* Clear PL1 CLAMP bit */ |
| 207 | PL1C = 0 |
| 208 | |
| 209 | /* Set PL1 to normal value */ |
| 210 | PL1V = SPL1 |
| 211 | |
| 212 | /* Set TAR to 0 */ |
| 213 | TARS = 0 |
| 214 | |
| 215 | /* Set _PPC to 0 */ |
| 216 | PPCM = 0 |
| 217 | \PPCN () |
| 218 | |
| 219 | Release (CTCM) |
| 220 | Return (1) |
| 221 | } |
Angel Pons | f239b5a | 2020-10-25 12:58:32 +0100 | [diff] [blame] | 222 | } |