blob: f9b587df3ada1c0d5790e9bffcd2253211e3699d [file] [log] [blame]
Duncan Laurie64bc26a2020-10-10 00:15:28 +00001/* 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 Wawrzynczak32f883e2021-12-02 16:19:47 -070012#include <intelblocks/pcie_rp.h>
13#include <soc/iomap.h>
Duncan Laurie64bc26a2020-10-10 00:15:28 +000014#include "chip.h"
15
Duncan Laurie64bc26a2020-10-10 00:15:28 +000016/* 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 Wawrzynczak32f883e2021-12-02 16:19:47 -070028/* ACPI path to the mutex that protects accesses to PMC ModPhy power gating registers */
29#define RTD3_MUTEX_PATH "\\_SB.PCI0.R3MX"
30
31enum modphy_pg_state {
32 PG_DISABLE = 0,
33 PG_ENABLE = 1,
34};
35
Duncan Laurie64bc26a2020-10-10 00:15:28 +000036/* Called from _ON to get PCIe link back to active state. */
37static 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. */
57static 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 Wawrzynczak32f883e2021-12-02 16:19:47 -070068/* Called from _ON/_OFF to disable/enable ModPHY power gating */
69static 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 Huang4bc9ac72022-01-21 00:23:15 -080084/* Method to enter L2/L3 */
85static 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 */
93static 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 */
101static 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 */
109static 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 Laurie64bc26a2020-10-10 00:15:28 +0000124static void
125pcie_rtd3_acpi_method_on(unsigned int pcie_rp,
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700126 const struct soc_intel_common_block_pcie_rtd3_config *config,
Kane Chen11be5562022-11-03 23:18:44 +0800127 enum pcie_rp_type rp_type,
128 const struct device *dev)
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000129{
Kane Chen11be5562022-11-03 23:18:44 +0800130 const struct device *parent = dev->bus->dev;
131
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000132 acpigen_write_method_serialized("_ON", 0);
133
Kane Chen11be5562022-11-03 23:18:44 +0800134 /* 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 Huangd1a74162022-01-21 14:54:32 -0800151 /* 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 Wawrzynczak32f883e2021-12-02 16:19:47 -0700158 /* 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 Laurie64bc26a2020-10-10 00:15:28 +0000162 /* 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 Wawrzynczak32f883e2021-12-02 16:19:47 -0700180 /* Trigger L23 ready exit flow unless disabled by config. */
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000181 if (!config->disable_l23)
182 pcie_rtd3_acpi_l23_exit();
183
Cliff Huangd1a74162022-01-21 14:54:32 -0800184 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 Laurie64bc26a2020-10-10 00:15:28 +0000194 acpigen_pop_len(); /* Method */
195}
196
197static void
198pcie_rtd3_acpi_method_off(int pcie_rp,
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700199 const struct soc_intel_common_block_pcie_rtd3_config *config,
200 enum pcie_rp_type rp_type)
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000201{
202 acpigen_write_method_serialized("_OFF", 0);
203
Cliff Huangd1a74162022-01-21 14:54:32 -0800204 /* 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 Laurie64bc26a2020-10-10 00:15:28 +0000212 /* 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 Wawrzynczak32f883e2021-12-02 16:19:47 -0700223 /* 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 Laurie64bc26a2020-10-10 00:15:28 +0000227 /* 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 Huangd1a74162022-01-21 14:54:32 -0800238 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 Laurie64bc26a2020-10-10 00:15:28 +0000254 acpigen_pop_len(); /* Method */
255}
256
257static void
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700258pcie_rtd3_acpi_method_status(const struct soc_intel_common_block_pcie_rtd3_config *config)
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000259{
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 Laurie64bc26a2020-10-10 00:15:28 +0000278 acpigen_write_else();
279 acpigen_write_return_op(ONE_OP);
280 acpigen_pop_len(); /* Else */
281
282 acpigen_pop_len(); /* Method */
283}
284
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700285static 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 Wawrzynczakb6a15a72021-12-08 10:43:56 -0700306static 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 Laurie64bc26a2020-10-10 00:15:28 +0000329static void pcie_rtd3_acpi_fill_ssdt(const struct device *dev)
330{
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700331 static bool mutex_created = false;
332
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000333 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 Wawrzynczakb6a15a72021-12-08 10:43:56 -0700350 int pcie_rp;
Kapil Porwal65bcb572022-11-28 18:53:40 +0530351 struct acpi_dp *dsd;
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000352
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 Qureshia9794602021-04-08 20:31:47 +0530366 if (config->srcclk_pin > CONFIG_MAX_PCIE_CLOCK_SRC) {
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000367 printk(BIOS_ERR, "%s: Invalid clock pin %u for %s.\n", __func__,
368 config->srcclk_pin, scope);
369 return;
370 }
371
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700372 const enum pcie_rp_type rp_type = soc_get_pcie_rp_type(parent);
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700373 pcie_rp = get_pcie_rp_pmc_idx(rp_type, parent);
Tim Wawrzynczakb3cd55b2022-01-20 14:06:29 -0700374 if (pcie_rp < 0) {
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700375 printk(BIOS_ERR, "%s: Unknown PCIe root port\n", __func__);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000376 return;
377 }
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800378 if (config->disable_l23) {
Angel Ponsd85319a2022-02-13 13:35:20 +0100379 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_L23) {
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800380 printk(BIOS_ERR, "%s: Can not export L23 methods\n", __func__);
381 return;
382 }
383 }
384 if (rp_type != PCIE_RP_PCH) {
Angel Ponsd85319a2022-02-13 13:35:20 +0100385 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_PSD0) {
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800386 printk(BIOS_ERR, "%s: Can not export PSD0 method\n", __func__);
387 return;
388 }
389 }
390 if (config->srcclk_pin == 0) {
Angel Ponsd85319a2022-02-13 13:35:20 +0100391 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_SRCK) {
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800392 printk(BIOS_ERR, "%s: Can not export SRCK method\n", __func__);
393 return;
394 }
395 }
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000396
397 printk(BIOS_INFO, "%s: Enable RTD3 for %s (%s)\n", scope, dev_path(parent),
398 config->desc ?: dev->chip_ops->name);
399
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700400 /* 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 Laurie64bc26a2020-10-10 00:15:28 +0000408 /* 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 Wawrzynczak32f883e2021-12-02 16:19:47 -0700414 /* Create OpRegions for MMIO accesses. */
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000415 acpigen_write_opregion(&opregion);
416 acpigen_write_field("PXCS", fieldlist, ARRAY_SIZE(fieldlist),
417 FIELD_ANYACC | FIELD_NOLOCK | FIELD_PRESERVE);
418
Angel Ponsd85319a2022-02-13 13:35:20 +0100419 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_L23) {
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800420 pcie_rtd3_acpi_method_dl23();
421 pcie_rtd3_acpi_method_l23d();
422 }
423
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700424 /* 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 Ponsd85319a2022-02-13 13:35:20 +0100428 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_PSD0)
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800429 pcie_rtd3_acpi_method_pds0(pcie_rp);
430
Angel Ponsd85319a2022-02-13 13:35:20 +0100431 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_SRCK)
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800432 pcie_rtd3_acpi_method_srck(pcie_rp, config);
433
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000434 /* 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 Huangd1a74162022-01-21 14:54:32 -0800436
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 Wawrzynczakb6a15a72021-12-08 10:43:56 -0700451 pcie_rtd3_acpi_method_status(config);
Kane Chen11be5562022-11-03 23:18:44 +0800452 pcie_rtd3_acpi_method_on(pcie_rp, config, rp_type, dev);
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700453 pcie_rtd3_acpi_method_off(pcie_rp, config, rp_type);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000454 acpigen_pop_len(); /* PowerResource */
455
456 /* Indicate to the OS that device supports hotplug in D3. */
457 dsd = acpi_dp_new_table("_DSD");
Kapil Porwal65bcb572022-11-28 18:53:40 +0530458 acpi_device_add_hotplug_support_in_d3(dsd);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000459
460 /* Indicate to the OS if the device provides an External facing port. */
Kapil Porwal65bcb572022-11-28 18:53:40 +0530461 if (config->add_acpi_external_facing_port)
462 acpi_device_add_external_facing_port(dsd);
Kapil Porwald7eacd72022-11-28 11:03:38 +0530463
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 Laurie64bc26a2020-10-10 00:15:28 +0000468 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 Wawrzynczak61083212021-08-05 09:40:19 -0600479 acpigen_write_name_integer("_S0W", ACPI_DEVICE_SLEEP_D3_COLD);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000480
Kapil Porwal65bcb572022-11-28 18:53:40 +0530481 acpi_device_add_storage_d3_enable(NULL);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000482
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
491static 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
497static 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
504static void pcie_rtd3_acpi_enable(struct device *dev)
505{
506 dev->ops = &pcie_rtd3_ops;
507}
508
509struct chip_operations soc_intel_common_block_pcie_rtd3_ops = {
510 CHIP_NAME("Intel PCIe Runtime D3")
511 .enable_dev = pcie_rtd3_acpi_enable
512};