Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #include <acpi/acpigen.h> |
| 4 | #include <acpi/acpi_device.h> |
| 5 | #include <console/console.h> |
| 6 | #include <device/device.h> |
| 7 | #include <device/pci_ids.h> |
| 8 | #include <device/pci_ops.h> |
| 9 | #include <device/pci.h> |
| 10 | #include <intelblocks/pmc.h> |
| 11 | #include <intelblocks/pmc_ipc.h> |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 12 | #include <intelblocks/pcie_rp.h> |
| 13 | #include <soc/iomap.h> |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 14 | #include "chip.h" |
| 15 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 16 | /* PCIe Root Port registers for link status and L23 control. */ |
| 17 | #define PCH_PCIE_CFG_LSTS 0x52 /* Link Status Register */ |
| 18 | #define PCH_PCIE_CFG_SPR 0xe0 /* Scratchpad */ |
| 19 | #define PCH_PCIE_CFG_RPPGEN 0xe2 /* Root Port Power Gating Enable */ |
| 20 | #define PCH_PCIE_CFG_LCAP_PN 0x4f /* Root Port Number */ |
| 21 | |
| 22 | /* ACPI register names corresponding to PCIe root port registers. */ |
| 23 | #define ACPI_REG_PCI_LINK_ACTIVE "LASX" /* Link active status */ |
| 24 | #define ACPI_REG_PCI_L23_RDY_ENTRY "L23E" /* L23_Rdy Entry Request */ |
| 25 | #define ACPI_REG_PCI_L23_RDY_DETECT "L23R" /* L23_Rdy Detect Transition */ |
| 26 | #define ACPI_REG_PCI_L23_SAVE_STATE "NCB7" /* Scratch bit to save L23 state */ |
| 27 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 28 | /* ACPI path to the mutex that protects accesses to PMC ModPhy power gating registers */ |
| 29 | #define RTD3_MUTEX_PATH "\\_SB.PCI0.R3MX" |
| 30 | |
| 31 | enum modphy_pg_state { |
| 32 | PG_DISABLE = 0, |
| 33 | PG_ENABLE = 1, |
| 34 | }; |
| 35 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 36 | /* Called from _ON to get PCIe link back to active state. */ |
| 37 | static void pcie_rtd3_acpi_l23_exit(void) |
| 38 | { |
| 39 | /* Skip if port is not in L2/L3. */ |
| 40 | acpigen_write_if_lequal_namestr_int(ACPI_REG_PCI_L23_SAVE_STATE, 1); |
| 41 | |
| 42 | /* Initiate L2/L3 Ready To Detect transition. */ |
| 43 | acpigen_write_store_int_to_namestr(1, ACPI_REG_PCI_L23_RDY_DETECT); |
| 44 | |
| 45 | /* Wait for transition to detect. */ |
| 46 | acpigen_write_delay_until_namestr_int(320, ACPI_REG_PCI_L23_RDY_DETECT, 0); |
| 47 | |
| 48 | acpigen_write_store_int_to_namestr(0, ACPI_REG_PCI_L23_SAVE_STATE); |
| 49 | |
| 50 | /* Once in detect, wait for link active. */ |
| 51 | acpigen_write_delay_until_namestr_int(128, ACPI_REG_PCI_LINK_ACTIVE, 1); |
| 52 | |
| 53 | acpigen_pop_len(); /* If */ |
| 54 | } |
| 55 | |
| 56 | /* Called from _OFF to put PCIe link into L2/L3 state. */ |
| 57 | static void pcie_rtd3_acpi_l23_entry(void) |
| 58 | { |
| 59 | /* Initiate L2/L3 Entry request. */ |
| 60 | acpigen_write_store_int_to_namestr(1, ACPI_REG_PCI_L23_RDY_ENTRY); |
| 61 | |
| 62 | /* Wait for L2/L3 Entry request to clear. */ |
| 63 | acpigen_write_delay_until_namestr_int(128, ACPI_REG_PCI_L23_RDY_ENTRY, 0); |
| 64 | |
| 65 | acpigen_write_store_int_to_namestr(1, ACPI_REG_PCI_L23_SAVE_STATE); |
| 66 | } |
| 67 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 68 | /* Called from _ON/_OFF to disable/enable ModPHY power gating */ |
| 69 | static void pcie_rtd3_enable_modphy_pg(unsigned int pcie_rp, enum modphy_pg_state state) |
| 70 | { |
| 71 | /* Enter the critical section */ |
| 72 | acpigen_emit_ext_op(ACQUIRE_OP); |
| 73 | acpigen_emit_namestring(RTD3_MUTEX_PATH); |
| 74 | acpigen_emit_word(ACPI_MUTEX_NO_TIMEOUT); |
| 75 | |
| 76 | acpigen_write_store_int_to_namestr(state, "EMPG"); |
| 77 | acpigen_write_delay_until_namestr_int(100, "AMPG", state); |
| 78 | |
| 79 | /* Exit the critical section */ |
| 80 | acpigen_emit_ext_op(RELEASE_OP); |
| 81 | acpigen_emit_namestring(RTD3_MUTEX_PATH); |
| 82 | } |
| 83 | |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 84 | /* Method to enter L2/L3 */ |
| 85 | static void pcie_rtd3_acpi_method_dl23(void) |
| 86 | { |
| 87 | acpigen_write_method_serialized("DL23", 0); |
| 88 | pcie_rtd3_acpi_l23_entry(); |
| 89 | acpigen_pop_len(); /* Method */ |
| 90 | } |
| 91 | |
| 92 | /* Method to exit L2/L3 */ |
| 93 | static void pcie_rtd3_acpi_method_l23d(void) |
| 94 | { |
| 95 | acpigen_write_method_serialized("L23D", 0); |
| 96 | pcie_rtd3_acpi_l23_exit(); |
| 97 | acpigen_pop_len(); /* Method */ |
| 98 | } |
| 99 | |
| 100 | /* Method to disable PCH modPHY power gating */ |
| 101 | static void pcie_rtd3_acpi_method_pds0(unsigned int pcie_rp) |
| 102 | { |
| 103 | acpigen_write_method_serialized("PSD0", 0); |
| 104 | pcie_rtd3_enable_modphy_pg(pcie_rp, PG_DISABLE); |
| 105 | acpigen_pop_len(); /* Method */ |
| 106 | } |
| 107 | |
| 108 | /* Method to enable/disable the source clock */ |
| 109 | static void pcie_rtd3_acpi_method_srck(unsigned int pcie_rp, |
| 110 | const struct soc_intel_common_block_pcie_rtd3_config *config) |
| 111 | { |
| 112 | acpigen_write_method_serialized("SRCK", 1); |
| 113 | |
| 114 | if (config->srcclk_pin >= 0) { |
| 115 | acpigen_write_if_lequal_op_op(ARG0_OP, 0); |
| 116 | pmc_ipc_acpi_set_pci_clock(pcie_rp, config->srcclk_pin, false); |
| 117 | acpigen_write_else(); |
| 118 | pmc_ipc_acpi_set_pci_clock(pcie_rp, config->srcclk_pin, true); |
| 119 | acpigen_pop_len(); /* If */ |
| 120 | } |
| 121 | acpigen_pop_len(); /* Method */ |
| 122 | } |
| 123 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 124 | static void |
| 125 | pcie_rtd3_acpi_method_on(unsigned int pcie_rp, |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 126 | const struct soc_intel_common_block_pcie_rtd3_config *config, |
Kane Chen | 11be556 | 2022-11-03 23:18:44 +0800 | [diff] [blame] | 127 | enum pcie_rp_type rp_type, |
| 128 | const struct device *dev) |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 129 | { |
Kane Chen | 11be556 | 2022-11-03 23:18:44 +0800 | [diff] [blame] | 130 | const struct device *parent = dev->bus->dev; |
| 131 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 132 | acpigen_write_method_serialized("_ON", 0); |
| 133 | |
Kane Chen | 11be556 | 2022-11-03 23:18:44 +0800 | [diff] [blame] | 134 | /* The _STA returns current power status of device, so we can skip _ON |
| 135 | * if _STA returns 1 |
| 136 | * Example: |
| 137 | * Local0 = \_SB.PCI0.RP01.RTD3._STA () |
| 138 | * If ((Local0 == One)) |
| 139 | * { |
| 140 | * Return (One) |
| 141 | * } |
| 142 | */ |
| 143 | acpigen_write_store(); |
| 144 | acpigen_emit_namestring(acpi_device_path_join(parent, "RTD3._STA")); |
| 145 | acpigen_emit_byte(LOCAL0_OP); |
| 146 | acpigen_write_if_lequal_op_int(LOCAL0_OP, ONE_OP); |
| 147 | acpigen_write_return_op(ONE_OP); |
| 148 | acpigen_write_if_end(); |
| 149 | |
| 150 | |
Cliff Huang | d1a7416 | 2022-01-21 14:54:32 -0800 | [diff] [blame] | 151 | /* When this feature is enabled, ONSK indicates if the previous _OFF was |
| 152 | * skipped. If so, since the device was not in Off state, and the current |
| 153 | * _ON can be skipped as well. |
| 154 | */ |
| 155 | if (config->skip_on_off_support) |
| 156 | acpigen_write_if_lequal_namestr_int("ONSK", 0); |
| 157 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 158 | /* Disable modPHY power gating for PCH RPs. */ |
| 159 | if (rp_type == PCIE_RP_PCH) |
| 160 | pcie_rtd3_enable_modphy_pg(pcie_rp, PG_DISABLE); |
| 161 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 162 | /* Assert enable GPIO to turn on device power. */ |
| 163 | if (config->enable_gpio.pin_count) { |
| 164 | acpigen_enable_tx_gpio(&config->enable_gpio); |
| 165 | if (config->enable_delay_ms) |
| 166 | acpigen_write_sleep(config->enable_delay_ms); |
| 167 | } |
| 168 | |
| 169 | /* Enable SRCCLK for root port if pin is defined. */ |
| 170 | if (config->srcclk_pin >= 0) |
| 171 | pmc_ipc_acpi_set_pci_clock(pcie_rp, config->srcclk_pin, true); |
| 172 | |
| 173 | /* De-assert reset GPIO to bring device out of reset. */ |
| 174 | if (config->reset_gpio.pin_count) { |
| 175 | acpigen_disable_tx_gpio(&config->reset_gpio); |
| 176 | if (config->reset_delay_ms) |
| 177 | acpigen_write_sleep(config->reset_delay_ms); |
| 178 | } |
| 179 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 180 | /* Trigger L23 ready exit flow unless disabled by config. */ |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 181 | if (!config->disable_l23) |
| 182 | pcie_rtd3_acpi_l23_exit(); |
| 183 | |
Cliff Huang | d1a7416 | 2022-01-21 14:54:32 -0800 | [diff] [blame] | 184 | if (config->skip_on_off_support) { |
| 185 | /* If current _ON is skipped, ONSK is decremented so that _ON will be |
| 186 | * executed normally until _OFF is skipped again. |
| 187 | */ |
| 188 | acpigen_write_else(); |
| 189 | acpigen_emit_byte(DECREMENT_OP); |
| 190 | acpigen_emit_namestring("ONSK"); |
| 191 | |
| 192 | acpigen_pop_len(); /* Else */ |
| 193 | } |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 194 | acpigen_pop_len(); /* Method */ |
| 195 | } |
| 196 | |
| 197 | static void |
| 198 | pcie_rtd3_acpi_method_off(int pcie_rp, |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 199 | const struct soc_intel_common_block_pcie_rtd3_config *config, |
| 200 | enum pcie_rp_type rp_type) |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 201 | { |
| 202 | acpigen_write_method_serialized("_OFF", 0); |
| 203 | |
Cliff Huang | d1a7416 | 2022-01-21 14:54:32 -0800 | [diff] [blame] | 204 | /* When this feature is enabled, ONSK is checked to see if the device |
| 205 | * wants _OFF to be skipped for once. ONSK is normally incremented in the |
| 206 | * device method, such as reset _RST, which is invoked during driver reload. |
| 207 | * In such case, _OFF needs to be avoided at the end of driver removal. |
| 208 | */ |
| 209 | if (config->skip_on_off_support) |
| 210 | acpigen_write_if_lequal_namestr_int("OFSK", 0); |
| 211 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 212 | /* Trigger L23 ready entry flow unless disabled by config. */ |
| 213 | if (!config->disable_l23) |
| 214 | pcie_rtd3_acpi_l23_entry(); |
| 215 | |
| 216 | /* Assert reset GPIO to place device into reset. */ |
| 217 | if (config->reset_gpio.pin_count) { |
| 218 | acpigen_enable_tx_gpio(&config->reset_gpio); |
| 219 | if (config->reset_off_delay_ms) |
| 220 | acpigen_write_sleep(config->reset_off_delay_ms); |
| 221 | } |
| 222 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 223 | /* Enable modPHY power gating for PCH RPs */ |
| 224 | if (rp_type == PCIE_RP_PCH) |
| 225 | pcie_rtd3_enable_modphy_pg(pcie_rp, PG_ENABLE); |
| 226 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 227 | /* Disable SRCCLK for this root port if pin is defined. */ |
| 228 | if (config->srcclk_pin >= 0) |
| 229 | pmc_ipc_acpi_set_pci_clock(pcie_rp, config->srcclk_pin, false); |
| 230 | |
| 231 | /* De-assert enable GPIO to turn off device power. */ |
| 232 | if (config->enable_gpio.pin_count) { |
| 233 | acpigen_disable_tx_gpio(&config->enable_gpio); |
| 234 | if (config->enable_off_delay_ms) |
| 235 | acpigen_write_sleep(config->enable_off_delay_ms); |
| 236 | } |
| 237 | |
Cliff Huang | d1a7416 | 2022-01-21 14:54:32 -0800 | [diff] [blame] | 238 | if (config->skip_on_off_support) { |
| 239 | /* If current _OFF is skipped, ONSK is incremented so that the |
| 240 | * following _ON will also be skipped. In addition, OFSK is decremented |
| 241 | * so that next _OFF will be executed normally until the device method |
| 242 | * increments OFSK again. |
| 243 | */ |
| 244 | acpigen_write_else(); |
| 245 | /* OFSK-- */ |
| 246 | acpigen_emit_byte(DECREMENT_OP); |
| 247 | acpigen_emit_namestring("OFSK"); |
| 248 | /* ONSK++ */ |
| 249 | acpigen_emit_byte(INCREMENT_OP); |
| 250 | acpigen_emit_namestring("ONSK"); |
| 251 | |
| 252 | acpigen_pop_len(); /* Else */ |
| 253 | } |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 254 | acpigen_pop_len(); /* Method */ |
| 255 | } |
| 256 | |
| 257 | static void |
Tim Wawrzynczak | b6a15a7 | 2021-12-08 10:43:56 -0700 | [diff] [blame] | 258 | pcie_rtd3_acpi_method_status(const struct soc_intel_common_block_pcie_rtd3_config *config) |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 259 | { |
| 260 | const struct acpi_gpio *gpio; |
| 261 | |
| 262 | acpigen_write_method("_STA", 0); |
| 263 | |
| 264 | /* Use enable GPIO for status if provided, otherwise use reset GPIO. */ |
| 265 | if (config->enable_gpio.pin_count) |
| 266 | gpio = &config->enable_gpio; |
| 267 | else |
| 268 | gpio = &config->reset_gpio; |
| 269 | |
| 270 | /* Read current GPIO value into Local0. */ |
| 271 | acpigen_get_tx_gpio(gpio); |
| 272 | |
| 273 | /* Ensure check works for both active low and active high GPIOs. */ |
| 274 | acpigen_write_store_int_to_op(gpio->active_low, LOCAL1_OP); |
| 275 | |
| 276 | acpigen_write_if_lequal_op_op(LOCAL0_OP, LOCAL1_OP); |
| 277 | acpigen_write_return_op(ZERO_OP); |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 278 | acpigen_write_else(); |
| 279 | acpigen_write_return_op(ONE_OP); |
| 280 | acpigen_pop_len(); /* Else */ |
| 281 | |
| 282 | acpigen_pop_len(); /* Method */ |
| 283 | } |
| 284 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 285 | static void write_modphy_opregion(unsigned int pcie_rp) |
| 286 | { |
| 287 | /* The register containing the Power Gate enable sequence bits is at |
| 288 | PCH_PWRM_BASE + 0x10D0, and the bits to check for sequence completion are at |
| 289 | PCH_PWRM_BASE + 0x10D4. */ |
| 290 | const struct opregion opregion = OPREGION("PMCP", SYSTEMMEMORY, |
| 291 | PCH_PWRM_BASE_ADDRESS + 0x1000, 0xff); |
| 292 | const struct fieldlist fieldlist[] = { |
| 293 | FIELDLIST_OFFSET(0xD0), |
| 294 | FIELDLIST_RESERVED(pcie_rp), |
| 295 | FIELDLIST_NAMESTR("EMPG", 1), /* Enable ModPHY Power Gate */ |
| 296 | FIELDLIST_OFFSET(0xD4), |
| 297 | FIELDLIST_RESERVED(pcie_rp), |
| 298 | FIELDLIST_NAMESTR("AMPG", 1), /* Is ModPHY Power Gate active? */ |
| 299 | }; |
| 300 | |
| 301 | acpigen_write_opregion(&opregion); |
| 302 | acpigen_write_field("PMCP", fieldlist, ARRAY_SIZE(fieldlist), |
| 303 | FIELD_DWORDACC | FIELD_NOLOCK | FIELD_PRESERVE); |
| 304 | } |
| 305 | |
Tim Wawrzynczak | b6a15a7 | 2021-12-08 10:43:56 -0700 | [diff] [blame] | 306 | static int get_pcie_rp_pmc_idx(enum pcie_rp_type rp_type, const struct device *dev) |
| 307 | { |
| 308 | int idx = -1; |
| 309 | |
| 310 | switch (rp_type) { |
| 311 | case PCIE_RP_PCH: |
| 312 | /* Read port number of root port that this device is attached to. */ |
| 313 | idx = pci_read_config8(dev, PCH_PCIE_CFG_LCAP_PN); |
| 314 | |
| 315 | /* Port number is 1-based, PMC IPC method expects 0-based. */ |
| 316 | idx--; |
| 317 | break; |
| 318 | case PCIE_RP_CPU: |
| 319 | /* CPU RPs are indexed by their "virtual wire index" to the PCH */ |
| 320 | idx = soc_get_cpu_rp_vw_idx(dev); |
| 321 | break; |
| 322 | default: |
| 323 | break; |
| 324 | } |
| 325 | |
| 326 | return idx; |
| 327 | } |
| 328 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 329 | static void pcie_rtd3_acpi_fill_ssdt(const struct device *dev) |
| 330 | { |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 331 | static bool mutex_created = false; |
| 332 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 333 | const struct soc_intel_common_block_pcie_rtd3_config *config = config_of(dev); |
| 334 | static const char *const power_res_states[] = {"_PR0"}; |
| 335 | const struct device *parent = dev->bus->dev; |
| 336 | const char *scope = acpi_device_path(parent); |
| 337 | const struct opregion opregion = OPREGION("PXCS", PCI_CONFIG, 0, 0xff); |
| 338 | const struct fieldlist fieldlist[] = { |
| 339 | FIELDLIST_OFFSET(PCH_PCIE_CFG_LSTS), |
| 340 | FIELDLIST_RESERVED(13), |
| 341 | FIELDLIST_NAMESTR(ACPI_REG_PCI_LINK_ACTIVE, 1), |
| 342 | FIELDLIST_OFFSET(PCH_PCIE_CFG_SPR), |
| 343 | FIELDLIST_RESERVED(7), |
| 344 | FIELDLIST_NAMESTR(ACPI_REG_PCI_L23_SAVE_STATE, 1), |
| 345 | FIELDLIST_OFFSET(PCH_PCIE_CFG_RPPGEN), |
| 346 | FIELDLIST_RESERVED(2), |
| 347 | FIELDLIST_NAMESTR(ACPI_REG_PCI_L23_RDY_ENTRY, 1), |
| 348 | FIELDLIST_NAMESTR(ACPI_REG_PCI_L23_RDY_DETECT, 1), |
| 349 | }; |
Tim Wawrzynczak | b6a15a7 | 2021-12-08 10:43:56 -0700 | [diff] [blame] | 350 | int pcie_rp; |
Kapil Porwal | 65bcb57 | 2022-11-28 18:53:40 +0530 | [diff] [blame^] | 351 | struct acpi_dp *dsd; |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 352 | |
| 353 | if (!is_dev_enabled(parent)) { |
| 354 | printk(BIOS_ERR, "%s: root port not enabled\n", __func__); |
| 355 | return; |
| 356 | } |
| 357 | if (!scope) { |
| 358 | printk(BIOS_ERR, "%s: root port scope not found\n", __func__); |
| 359 | return; |
| 360 | } |
| 361 | if (!config->enable_gpio.pin_count && !config->reset_gpio.pin_count) { |
| 362 | printk(BIOS_ERR, "%s: Enable and/or Reset GPIO required for %s.\n", |
| 363 | __func__, scope); |
| 364 | return; |
| 365 | } |
Rizwan Qureshi | a979460 | 2021-04-08 20:31:47 +0530 | [diff] [blame] | 366 | if (config->srcclk_pin > CONFIG_MAX_PCIE_CLOCK_SRC) { |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 367 | printk(BIOS_ERR, "%s: Invalid clock pin %u for %s.\n", __func__, |
| 368 | config->srcclk_pin, scope); |
| 369 | return; |
| 370 | } |
| 371 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 372 | const enum pcie_rp_type rp_type = soc_get_pcie_rp_type(parent); |
Tim Wawrzynczak | b6a15a7 | 2021-12-08 10:43:56 -0700 | [diff] [blame] | 373 | pcie_rp = get_pcie_rp_pmc_idx(rp_type, parent); |
Tim Wawrzynczak | b3cd55b | 2022-01-20 14:06:29 -0700 | [diff] [blame] | 374 | if (pcie_rp < 0) { |
Tim Wawrzynczak | b6a15a7 | 2021-12-08 10:43:56 -0700 | [diff] [blame] | 375 | printk(BIOS_ERR, "%s: Unknown PCIe root port\n", __func__); |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 376 | return; |
| 377 | } |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 378 | if (config->disable_l23) { |
Angel Pons | d85319a | 2022-02-13 13:35:20 +0100 | [diff] [blame] | 379 | if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_L23) { |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 380 | printk(BIOS_ERR, "%s: Can not export L23 methods\n", __func__); |
| 381 | return; |
| 382 | } |
| 383 | } |
| 384 | if (rp_type != PCIE_RP_PCH) { |
Angel Pons | d85319a | 2022-02-13 13:35:20 +0100 | [diff] [blame] | 385 | if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_PSD0) { |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 386 | printk(BIOS_ERR, "%s: Can not export PSD0 method\n", __func__); |
| 387 | return; |
| 388 | } |
| 389 | } |
| 390 | if (config->srcclk_pin == 0) { |
Angel Pons | d85319a | 2022-02-13 13:35:20 +0100 | [diff] [blame] | 391 | if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_SRCK) { |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 392 | printk(BIOS_ERR, "%s: Can not export SRCK method\n", __func__); |
| 393 | return; |
| 394 | } |
| 395 | } |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 396 | |
| 397 | printk(BIOS_INFO, "%s: Enable RTD3 for %s (%s)\n", scope, dev_path(parent), |
| 398 | config->desc ?: dev->chip_ops->name); |
| 399 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 400 | /* Create a mutex for exclusive access to the PMC registers. */ |
| 401 | if (rp_type == PCIE_RP_PCH && !mutex_created) { |
| 402 | acpigen_write_scope("\\_SB.PCI0"); |
| 403 | acpigen_write_mutex("R3MX", 0); |
| 404 | acpigen_write_scope_end(); |
| 405 | mutex_created = true; |
| 406 | } |
| 407 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 408 | /* The RTD3 power resource is added to the root port, not the device. */ |
| 409 | acpigen_write_scope(scope); |
| 410 | |
| 411 | if (config->desc) |
| 412 | acpigen_write_name_string("_DDN", config->desc); |
| 413 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 414 | /* Create OpRegions for MMIO accesses. */ |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 415 | acpigen_write_opregion(&opregion); |
| 416 | acpigen_write_field("PXCS", fieldlist, ARRAY_SIZE(fieldlist), |
| 417 | FIELD_ANYACC | FIELD_NOLOCK | FIELD_PRESERVE); |
| 418 | |
Angel Pons | d85319a | 2022-02-13 13:35:20 +0100 | [diff] [blame] | 419 | if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_L23) { |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 420 | pcie_rtd3_acpi_method_dl23(); |
| 421 | pcie_rtd3_acpi_method_l23d(); |
| 422 | } |
| 423 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 424 | /* Create the OpRegion to access the ModPHY PG registers (PCH RPs only) */ |
| 425 | if (rp_type == PCIE_RP_PCH) |
| 426 | write_modphy_opregion(pcie_rp); |
| 427 | |
Angel Pons | d85319a | 2022-02-13 13:35:20 +0100 | [diff] [blame] | 428 | if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_PSD0) |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 429 | pcie_rtd3_acpi_method_pds0(pcie_rp); |
| 430 | |
Angel Pons | d85319a | 2022-02-13 13:35:20 +0100 | [diff] [blame] | 431 | if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_SRCK) |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 432 | pcie_rtd3_acpi_method_srck(pcie_rp, config); |
| 433 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 434 | /* ACPI Power Resource for controlling the attached device power. */ |
| 435 | acpigen_write_power_res("RTD3", 0, 0, power_res_states, ARRAY_SIZE(power_res_states)); |
Cliff Huang | d1a7416 | 2022-01-21 14:54:32 -0800 | [diff] [blame] | 436 | |
| 437 | if (config->skip_on_off_support) { |
| 438 | /* OFSK: 0 = _OFF Method will be executed normally when called; |
| 439 | * >1 = _OFF will be skipped. |
| 440 | * _OFF Method to decrement OFSK and increment ONSK if the |
| 441 | * current execution is skipped. |
| 442 | * ONSK: 0 = _ON Method will be executed normally when called; |
| 443 | * >1 = _ONF will be skipped. |
| 444 | * _ON Method to decrement ONSK if the current execution is |
| 445 | * skipped. |
| 446 | */ |
| 447 | acpigen_write_name_integer("ONSK", 0); |
| 448 | acpigen_write_name_integer("OFSK", 0); |
| 449 | } |
| 450 | |
Tim Wawrzynczak | b6a15a7 | 2021-12-08 10:43:56 -0700 | [diff] [blame] | 451 | pcie_rtd3_acpi_method_status(config); |
Kane Chen | 11be556 | 2022-11-03 23:18:44 +0800 | [diff] [blame] | 452 | pcie_rtd3_acpi_method_on(pcie_rp, config, rp_type, dev); |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 453 | pcie_rtd3_acpi_method_off(pcie_rp, config, rp_type); |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 454 | acpigen_pop_len(); /* PowerResource */ |
| 455 | |
| 456 | /* Indicate to the OS that device supports hotplug in D3. */ |
| 457 | dsd = acpi_dp_new_table("_DSD"); |
Kapil Porwal | 65bcb57 | 2022-11-28 18:53:40 +0530 | [diff] [blame^] | 458 | acpi_device_add_hotplug_support_in_d3(dsd); |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 459 | |
| 460 | /* Indicate to the OS if the device provides an External facing port. */ |
Kapil Porwal | 65bcb57 | 2022-11-28 18:53:40 +0530 | [diff] [blame^] | 461 | if (config->add_acpi_external_facing_port) |
| 462 | acpi_device_add_external_facing_port(dsd); |
Kapil Porwal | d7eacd7 | 2022-11-28 11:03:38 +0530 | [diff] [blame] | 463 | |
| 464 | /* Indicate to the OS if the device has DMA property. */ |
| 465 | if (config->add_acpi_dma_property) |
| 466 | acpi_device_add_dma_property(dsd); |
| 467 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 468 | acpi_dp_write(dsd); |
| 469 | |
| 470 | /* |
| 471 | * Check the sibling device on the root port to see if it is storage class and add the |
| 472 | * property for the OS to enable storage D3, or allow it to be enabled by config. |
| 473 | */ |
| 474 | if (config->is_storage |
| 475 | || (dev->sibling && (dev->sibling->class >> 16) == PCI_BASE_CLASS_STORAGE)) { |
| 476 | acpigen_write_device(acpi_device_name(dev)); |
| 477 | acpigen_write_ADR(0); |
| 478 | acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON); |
Tim Wawrzynczak | 6108321 | 2021-08-05 09:40:19 -0600 | [diff] [blame] | 479 | acpigen_write_name_integer("_S0W", ACPI_DEVICE_SLEEP_D3_COLD); |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 480 | |
Kapil Porwal | 65bcb57 | 2022-11-28 18:53:40 +0530 | [diff] [blame^] | 481 | acpi_device_add_storage_d3_enable(NULL); |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 482 | |
| 483 | acpigen_pop_len(); /* Device */ |
| 484 | |
| 485 | printk(BIOS_INFO, "%s: Added StorageD3Enable property\n", scope); |
| 486 | } |
| 487 | |
| 488 | acpigen_pop_len(); /* Scope */ |
| 489 | } |
| 490 | |
| 491 | static const char *pcie_rtd3_acpi_name(const struct device *dev) |
| 492 | { |
| 493 | /* Attached device name must be "PXSX" for the Linux Kernel to recognize it. */ |
| 494 | return "PXSX"; |
| 495 | } |
| 496 | |
| 497 | static struct device_operations pcie_rtd3_ops = { |
| 498 | .read_resources = noop_read_resources, |
| 499 | .set_resources = noop_set_resources, |
| 500 | .acpi_fill_ssdt = pcie_rtd3_acpi_fill_ssdt, |
| 501 | .acpi_name = pcie_rtd3_acpi_name, |
| 502 | }; |
| 503 | |
| 504 | static void pcie_rtd3_acpi_enable(struct device *dev) |
| 505 | { |
| 506 | dev->ops = &pcie_rtd3_ops; |
| 507 | } |
| 508 | |
| 509 | struct chip_operations soc_intel_common_block_pcie_rtd3_ops = { |
| 510 | CHIP_NAME("Intel PCIe Runtime D3") |
| 511 | .enable_dev = pcie_rtd3_acpi_enable |
| 512 | }; |