blob: 7a64734b6e57ea69a6b6e4656557328be8548e39 [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
16/*
17 * The "ExternalFacingPort" and "HotPlugSupportInD3" properties are defined at
18 * https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports
19 */
20#define PCIE_EXTERNAL_PORT_UUID "EFCC06CC-73AC-4BC3-BFF0-76143807C389"
21#define PCIE_EXTERNAL_PORT_PROPERTY "ExternalFacingPort"
22
23#define PCIE_HOTPLUG_IN_D3_UUID "6211E2C0-58A3-4AF3-90E1-927A4E0C55A4"
24#define PCIE_HOTPLUG_IN_D3_PROPERTY "HotPlugSupportInD3"
25
26/*
27 * This UUID and the resulting ACPI Device Property is defined by the
28 * Power Management for Storage Hardware Devices:
29 *
30 * https://docs.microsoft.com/en-us/windows-hardware/design/component-guidelines/power-management-for-storage-hardware-devices-intro
31 */
32#define PCIE_RTD3_STORAGE_UUID "5025030F-842F-4AB4-A561-99A5189762D0"
33#define PCIE_RTD3_STORAGE_PROPERTY "StorageD3Enable"
34
35/* PCIe Root Port registers for link status and L23 control. */
36#define PCH_PCIE_CFG_LSTS 0x52 /* Link Status Register */
37#define PCH_PCIE_CFG_SPR 0xe0 /* Scratchpad */
38#define PCH_PCIE_CFG_RPPGEN 0xe2 /* Root Port Power Gating Enable */
39#define PCH_PCIE_CFG_LCAP_PN 0x4f /* Root Port Number */
40
41/* ACPI register names corresponding to PCIe root port registers. */
42#define ACPI_REG_PCI_LINK_ACTIVE "LASX" /* Link active status */
43#define ACPI_REG_PCI_L23_RDY_ENTRY "L23E" /* L23_Rdy Entry Request */
44#define ACPI_REG_PCI_L23_RDY_DETECT "L23R" /* L23_Rdy Detect Transition */
45#define ACPI_REG_PCI_L23_SAVE_STATE "NCB7" /* Scratch bit to save L23 state */
46
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -070047/* ACPI path to the mutex that protects accesses to PMC ModPhy power gating registers */
48#define RTD3_MUTEX_PATH "\\_SB.PCI0.R3MX"
49
50enum modphy_pg_state {
51 PG_DISABLE = 0,
52 PG_ENABLE = 1,
53};
54
Duncan Laurie64bc26a2020-10-10 00:15:28 +000055/* Called from _ON to get PCIe link back to active state. */
56static void pcie_rtd3_acpi_l23_exit(void)
57{
58 /* Skip if port is not in L2/L3. */
59 acpigen_write_if_lequal_namestr_int(ACPI_REG_PCI_L23_SAVE_STATE, 1);
60
61 /* Initiate L2/L3 Ready To Detect transition. */
62 acpigen_write_store_int_to_namestr(1, ACPI_REG_PCI_L23_RDY_DETECT);
63
64 /* Wait for transition to detect. */
65 acpigen_write_delay_until_namestr_int(320, ACPI_REG_PCI_L23_RDY_DETECT, 0);
66
67 acpigen_write_store_int_to_namestr(0, ACPI_REG_PCI_L23_SAVE_STATE);
68
69 /* Once in detect, wait for link active. */
70 acpigen_write_delay_until_namestr_int(128, ACPI_REG_PCI_LINK_ACTIVE, 1);
71
72 acpigen_pop_len(); /* If */
73}
74
75/* Called from _OFF to put PCIe link into L2/L3 state. */
76static void pcie_rtd3_acpi_l23_entry(void)
77{
78 /* Initiate L2/L3 Entry request. */
79 acpigen_write_store_int_to_namestr(1, ACPI_REG_PCI_L23_RDY_ENTRY);
80
81 /* Wait for L2/L3 Entry request to clear. */
82 acpigen_write_delay_until_namestr_int(128, ACPI_REG_PCI_L23_RDY_ENTRY, 0);
83
84 acpigen_write_store_int_to_namestr(1, ACPI_REG_PCI_L23_SAVE_STATE);
85}
86
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -070087/* Called from _ON/_OFF to disable/enable ModPHY power gating */
88static void pcie_rtd3_enable_modphy_pg(unsigned int pcie_rp, enum modphy_pg_state state)
89{
90 /* Enter the critical section */
91 acpigen_emit_ext_op(ACQUIRE_OP);
92 acpigen_emit_namestring(RTD3_MUTEX_PATH);
93 acpigen_emit_word(ACPI_MUTEX_NO_TIMEOUT);
94
95 acpigen_write_store_int_to_namestr(state, "EMPG");
96 acpigen_write_delay_until_namestr_int(100, "AMPG", state);
97
98 /* Exit the critical section */
99 acpigen_emit_ext_op(RELEASE_OP);
100 acpigen_emit_namestring(RTD3_MUTEX_PATH);
101}
102
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800103/* Method to enter L2/L3 */
104static void pcie_rtd3_acpi_method_dl23(void)
105{
106 acpigen_write_method_serialized("DL23", 0);
107 pcie_rtd3_acpi_l23_entry();
108 acpigen_pop_len(); /* Method */
109}
110
111/* Method to exit L2/L3 */
112static void pcie_rtd3_acpi_method_l23d(void)
113{
114 acpigen_write_method_serialized("L23D", 0);
115 pcie_rtd3_acpi_l23_exit();
116 acpigen_pop_len(); /* Method */
117}
118
119/* Method to disable PCH modPHY power gating */
120static void pcie_rtd3_acpi_method_pds0(unsigned int pcie_rp)
121{
122 acpigen_write_method_serialized("PSD0", 0);
123 pcie_rtd3_enable_modphy_pg(pcie_rp, PG_DISABLE);
124 acpigen_pop_len(); /* Method */
125}
126
127/* Method to enable/disable the source clock */
128static void pcie_rtd3_acpi_method_srck(unsigned int pcie_rp,
129 const struct soc_intel_common_block_pcie_rtd3_config *config)
130{
131 acpigen_write_method_serialized("SRCK", 1);
132
133 if (config->srcclk_pin >= 0) {
134 acpigen_write_if_lequal_op_op(ARG0_OP, 0);
135 pmc_ipc_acpi_set_pci_clock(pcie_rp, config->srcclk_pin, false);
136 acpigen_write_else();
137 pmc_ipc_acpi_set_pci_clock(pcie_rp, config->srcclk_pin, true);
138 acpigen_pop_len(); /* If */
139 }
140 acpigen_pop_len(); /* Method */
141}
142
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000143static void
144pcie_rtd3_acpi_method_on(unsigned int pcie_rp,
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700145 const struct soc_intel_common_block_pcie_rtd3_config *config,
Kane Chen11be5562022-11-03 23:18:44 +0800146 enum pcie_rp_type rp_type,
147 const struct device *dev)
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000148{
Kane Chen11be5562022-11-03 23:18:44 +0800149 const struct device *parent = dev->bus->dev;
150
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000151 acpigen_write_method_serialized("_ON", 0);
152
Kane Chen11be5562022-11-03 23:18:44 +0800153 /* The _STA returns current power status of device, so we can skip _ON
154 * if _STA returns 1
155 * Example:
156 * Local0 = \_SB.PCI0.RP01.RTD3._STA ()
157 * If ((Local0 == One))
158 * {
159 * Return (One)
160 * }
161 */
162 acpigen_write_store();
163 acpigen_emit_namestring(acpi_device_path_join(parent, "RTD3._STA"));
164 acpigen_emit_byte(LOCAL0_OP);
165 acpigen_write_if_lequal_op_int(LOCAL0_OP, ONE_OP);
166 acpigen_write_return_op(ONE_OP);
167 acpigen_write_if_end();
168
169
Cliff Huangd1a74162022-01-21 14:54:32 -0800170 /* When this feature is enabled, ONSK indicates if the previous _OFF was
171 * skipped. If so, since the device was not in Off state, and the current
172 * _ON can be skipped as well.
173 */
174 if (config->skip_on_off_support)
175 acpigen_write_if_lequal_namestr_int("ONSK", 0);
176
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700177 /* Disable modPHY power gating for PCH RPs. */
178 if (rp_type == PCIE_RP_PCH)
179 pcie_rtd3_enable_modphy_pg(pcie_rp, PG_DISABLE);
180
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000181 /* Assert enable GPIO to turn on device power. */
182 if (config->enable_gpio.pin_count) {
183 acpigen_enable_tx_gpio(&config->enable_gpio);
184 if (config->enable_delay_ms)
185 acpigen_write_sleep(config->enable_delay_ms);
186 }
187
188 /* Enable SRCCLK for root port if pin is defined. */
189 if (config->srcclk_pin >= 0)
190 pmc_ipc_acpi_set_pci_clock(pcie_rp, config->srcclk_pin, true);
191
192 /* De-assert reset GPIO to bring device out of reset. */
193 if (config->reset_gpio.pin_count) {
194 acpigen_disable_tx_gpio(&config->reset_gpio);
195 if (config->reset_delay_ms)
196 acpigen_write_sleep(config->reset_delay_ms);
197 }
198
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700199 /* Trigger L23 ready exit flow unless disabled by config. */
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000200 if (!config->disable_l23)
201 pcie_rtd3_acpi_l23_exit();
202
Cliff Huangd1a74162022-01-21 14:54:32 -0800203 if (config->skip_on_off_support) {
204 /* If current _ON is skipped, ONSK is decremented so that _ON will be
205 * executed normally until _OFF is skipped again.
206 */
207 acpigen_write_else();
208 acpigen_emit_byte(DECREMENT_OP);
209 acpigen_emit_namestring("ONSK");
210
211 acpigen_pop_len(); /* Else */
212 }
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000213 acpigen_pop_len(); /* Method */
214}
215
216static void
217pcie_rtd3_acpi_method_off(int pcie_rp,
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700218 const struct soc_intel_common_block_pcie_rtd3_config *config,
219 enum pcie_rp_type rp_type)
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000220{
221 acpigen_write_method_serialized("_OFF", 0);
222
Cliff Huangd1a74162022-01-21 14:54:32 -0800223 /* When this feature is enabled, ONSK is checked to see if the device
224 * wants _OFF to be skipped for once. ONSK is normally incremented in the
225 * device method, such as reset _RST, which is invoked during driver reload.
226 * In such case, _OFF needs to be avoided at the end of driver removal.
227 */
228 if (config->skip_on_off_support)
229 acpigen_write_if_lequal_namestr_int("OFSK", 0);
230
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000231 /* Trigger L23 ready entry flow unless disabled by config. */
232 if (!config->disable_l23)
233 pcie_rtd3_acpi_l23_entry();
234
235 /* Assert reset GPIO to place device into reset. */
236 if (config->reset_gpio.pin_count) {
237 acpigen_enable_tx_gpio(&config->reset_gpio);
238 if (config->reset_off_delay_ms)
239 acpigen_write_sleep(config->reset_off_delay_ms);
240 }
241
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700242 /* Enable modPHY power gating for PCH RPs */
243 if (rp_type == PCIE_RP_PCH)
244 pcie_rtd3_enable_modphy_pg(pcie_rp, PG_ENABLE);
245
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000246 /* Disable SRCCLK for this root port if pin is defined. */
247 if (config->srcclk_pin >= 0)
248 pmc_ipc_acpi_set_pci_clock(pcie_rp, config->srcclk_pin, false);
249
250 /* De-assert enable GPIO to turn off device power. */
251 if (config->enable_gpio.pin_count) {
252 acpigen_disable_tx_gpio(&config->enable_gpio);
253 if (config->enable_off_delay_ms)
254 acpigen_write_sleep(config->enable_off_delay_ms);
255 }
256
Cliff Huangd1a74162022-01-21 14:54:32 -0800257 if (config->skip_on_off_support) {
258 /* If current _OFF is skipped, ONSK is incremented so that the
259 * following _ON will also be skipped. In addition, OFSK is decremented
260 * so that next _OFF will be executed normally until the device method
261 * increments OFSK again.
262 */
263 acpigen_write_else();
264 /* OFSK-- */
265 acpigen_emit_byte(DECREMENT_OP);
266 acpigen_emit_namestring("OFSK");
267 /* ONSK++ */
268 acpigen_emit_byte(INCREMENT_OP);
269 acpigen_emit_namestring("ONSK");
270
271 acpigen_pop_len(); /* Else */
272 }
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000273 acpigen_pop_len(); /* Method */
274}
275
276static void
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700277pcie_rtd3_acpi_method_status(const struct soc_intel_common_block_pcie_rtd3_config *config)
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000278{
279 const struct acpi_gpio *gpio;
280
281 acpigen_write_method("_STA", 0);
282
283 /* Use enable GPIO for status if provided, otherwise use reset GPIO. */
284 if (config->enable_gpio.pin_count)
285 gpio = &config->enable_gpio;
286 else
287 gpio = &config->reset_gpio;
288
289 /* Read current GPIO value into Local0. */
290 acpigen_get_tx_gpio(gpio);
291
292 /* Ensure check works for both active low and active high GPIOs. */
293 acpigen_write_store_int_to_op(gpio->active_low, LOCAL1_OP);
294
295 acpigen_write_if_lequal_op_op(LOCAL0_OP, LOCAL1_OP);
296 acpigen_write_return_op(ZERO_OP);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000297 acpigen_write_else();
298 acpigen_write_return_op(ONE_OP);
299 acpigen_pop_len(); /* Else */
300
301 acpigen_pop_len(); /* Method */
302}
303
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700304static void write_modphy_opregion(unsigned int pcie_rp)
305{
306 /* The register containing the Power Gate enable sequence bits is at
307 PCH_PWRM_BASE + 0x10D0, and the bits to check for sequence completion are at
308 PCH_PWRM_BASE + 0x10D4. */
309 const struct opregion opregion = OPREGION("PMCP", SYSTEMMEMORY,
310 PCH_PWRM_BASE_ADDRESS + 0x1000, 0xff);
311 const struct fieldlist fieldlist[] = {
312 FIELDLIST_OFFSET(0xD0),
313 FIELDLIST_RESERVED(pcie_rp),
314 FIELDLIST_NAMESTR("EMPG", 1), /* Enable ModPHY Power Gate */
315 FIELDLIST_OFFSET(0xD4),
316 FIELDLIST_RESERVED(pcie_rp),
317 FIELDLIST_NAMESTR("AMPG", 1), /* Is ModPHY Power Gate active? */
318 };
319
320 acpigen_write_opregion(&opregion);
321 acpigen_write_field("PMCP", fieldlist, ARRAY_SIZE(fieldlist),
322 FIELD_DWORDACC | FIELD_NOLOCK | FIELD_PRESERVE);
323}
324
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700325static int get_pcie_rp_pmc_idx(enum pcie_rp_type rp_type, const struct device *dev)
326{
327 int idx = -1;
328
329 switch (rp_type) {
330 case PCIE_RP_PCH:
331 /* Read port number of root port that this device is attached to. */
332 idx = pci_read_config8(dev, PCH_PCIE_CFG_LCAP_PN);
333
334 /* Port number is 1-based, PMC IPC method expects 0-based. */
335 idx--;
336 break;
337 case PCIE_RP_CPU:
338 /* CPU RPs are indexed by their "virtual wire index" to the PCH */
339 idx = soc_get_cpu_rp_vw_idx(dev);
340 break;
341 default:
342 break;
343 }
344
345 return idx;
346}
347
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000348static void pcie_rtd3_acpi_fill_ssdt(const struct device *dev)
349{
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700350 static bool mutex_created = false;
351
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000352 const struct soc_intel_common_block_pcie_rtd3_config *config = config_of(dev);
353 static const char *const power_res_states[] = {"_PR0"};
354 const struct device *parent = dev->bus->dev;
355 const char *scope = acpi_device_path(parent);
356 const struct opregion opregion = OPREGION("PXCS", PCI_CONFIG, 0, 0xff);
357 const struct fieldlist fieldlist[] = {
358 FIELDLIST_OFFSET(PCH_PCIE_CFG_LSTS),
359 FIELDLIST_RESERVED(13),
360 FIELDLIST_NAMESTR(ACPI_REG_PCI_LINK_ACTIVE, 1),
361 FIELDLIST_OFFSET(PCH_PCIE_CFG_SPR),
362 FIELDLIST_RESERVED(7),
363 FIELDLIST_NAMESTR(ACPI_REG_PCI_L23_SAVE_STATE, 1),
364 FIELDLIST_OFFSET(PCH_PCIE_CFG_RPPGEN),
365 FIELDLIST_RESERVED(2),
366 FIELDLIST_NAMESTR(ACPI_REG_PCI_L23_RDY_ENTRY, 1),
367 FIELDLIST_NAMESTR(ACPI_REG_PCI_L23_RDY_DETECT, 1),
368 };
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700369 int pcie_rp;
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000370 struct acpi_dp *dsd, *pkg;
371
372 if (!is_dev_enabled(parent)) {
373 printk(BIOS_ERR, "%s: root port not enabled\n", __func__);
374 return;
375 }
376 if (!scope) {
377 printk(BIOS_ERR, "%s: root port scope not found\n", __func__);
378 return;
379 }
380 if (!config->enable_gpio.pin_count && !config->reset_gpio.pin_count) {
381 printk(BIOS_ERR, "%s: Enable and/or Reset GPIO required for %s.\n",
382 __func__, scope);
383 return;
384 }
Rizwan Qureshia9794602021-04-08 20:31:47 +0530385 if (config->srcclk_pin > CONFIG_MAX_PCIE_CLOCK_SRC) {
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000386 printk(BIOS_ERR, "%s: Invalid clock pin %u for %s.\n", __func__,
387 config->srcclk_pin, scope);
388 return;
389 }
390
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700391 const enum pcie_rp_type rp_type = soc_get_pcie_rp_type(parent);
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700392 pcie_rp = get_pcie_rp_pmc_idx(rp_type, parent);
Tim Wawrzynczakb3cd55b2022-01-20 14:06:29 -0700393 if (pcie_rp < 0) {
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700394 printk(BIOS_ERR, "%s: Unknown PCIe root port\n", __func__);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000395 return;
396 }
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800397 if (config->disable_l23) {
Angel Ponsd85319a2022-02-13 13:35:20 +0100398 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_L23) {
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800399 printk(BIOS_ERR, "%s: Can not export L23 methods\n", __func__);
400 return;
401 }
402 }
403 if (rp_type != PCIE_RP_PCH) {
Angel Ponsd85319a2022-02-13 13:35:20 +0100404 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_PSD0) {
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800405 printk(BIOS_ERR, "%s: Can not export PSD0 method\n", __func__);
406 return;
407 }
408 }
409 if (config->srcclk_pin == 0) {
Angel Ponsd85319a2022-02-13 13:35:20 +0100410 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_SRCK) {
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800411 printk(BIOS_ERR, "%s: Can not export SRCK method\n", __func__);
412 return;
413 }
414 }
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000415
416 printk(BIOS_INFO, "%s: Enable RTD3 for %s (%s)\n", scope, dev_path(parent),
417 config->desc ?: dev->chip_ops->name);
418
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700419 /* Create a mutex for exclusive access to the PMC registers. */
420 if (rp_type == PCIE_RP_PCH && !mutex_created) {
421 acpigen_write_scope("\\_SB.PCI0");
422 acpigen_write_mutex("R3MX", 0);
423 acpigen_write_scope_end();
424 mutex_created = true;
425 }
426
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000427 /* The RTD3 power resource is added to the root port, not the device. */
428 acpigen_write_scope(scope);
429
430 if (config->desc)
431 acpigen_write_name_string("_DDN", config->desc);
432
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700433 /* Create OpRegions for MMIO accesses. */
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000434 acpigen_write_opregion(&opregion);
435 acpigen_write_field("PXCS", fieldlist, ARRAY_SIZE(fieldlist),
436 FIELD_ANYACC | FIELD_NOLOCK | FIELD_PRESERVE);
437
Angel Ponsd85319a2022-02-13 13:35:20 +0100438 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_L23) {
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800439 pcie_rtd3_acpi_method_dl23();
440 pcie_rtd3_acpi_method_l23d();
441 }
442
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700443 /* Create the OpRegion to access the ModPHY PG registers (PCH RPs only) */
444 if (rp_type == PCIE_RP_PCH)
445 write_modphy_opregion(pcie_rp);
446
Angel Ponsd85319a2022-02-13 13:35:20 +0100447 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_PSD0)
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800448 pcie_rtd3_acpi_method_pds0(pcie_rp);
449
Angel Ponsd85319a2022-02-13 13:35:20 +0100450 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_SRCK)
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800451 pcie_rtd3_acpi_method_srck(pcie_rp, config);
452
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000453 /* ACPI Power Resource for controlling the attached device power. */
454 acpigen_write_power_res("RTD3", 0, 0, power_res_states, ARRAY_SIZE(power_res_states));
Cliff Huangd1a74162022-01-21 14:54:32 -0800455
456 if (config->skip_on_off_support) {
457 /* OFSK: 0 = _OFF Method will be executed normally when called;
458 * >1 = _OFF will be skipped.
459 * _OFF Method to decrement OFSK and increment ONSK if the
460 * current execution is skipped.
461 * ONSK: 0 = _ON Method will be executed normally when called;
462 * >1 = _ONF will be skipped.
463 * _ON Method to decrement ONSK if the current execution is
464 * skipped.
465 */
466 acpigen_write_name_integer("ONSK", 0);
467 acpigen_write_name_integer("OFSK", 0);
468 }
469
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700470 pcie_rtd3_acpi_method_status(config);
Kane Chen11be5562022-11-03 23:18:44 +0800471 pcie_rtd3_acpi_method_on(pcie_rp, config, rp_type, dev);
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700472 pcie_rtd3_acpi_method_off(pcie_rp, config, rp_type);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000473 acpigen_pop_len(); /* PowerResource */
474
475 /* Indicate to the OS that device supports hotplug in D3. */
476 dsd = acpi_dp_new_table("_DSD");
477 pkg = acpi_dp_new_table(PCIE_HOTPLUG_IN_D3_UUID);
478 acpi_dp_add_integer(pkg, PCIE_HOTPLUG_IN_D3_PROPERTY, 1);
479 acpi_dp_add_package(dsd, pkg);
480
481 /* Indicate to the OS if the device provides an External facing port. */
482 if (config->is_external) {
483 pkg = acpi_dp_new_table(PCIE_EXTERNAL_PORT_UUID);
484 acpi_dp_add_integer(pkg, PCIE_EXTERNAL_PORT_PROPERTY, 1);
485 acpi_dp_add_package(dsd, pkg);
486 }
487 acpi_dp_write(dsd);
488
489 /*
490 * Check the sibling device on the root port to see if it is storage class and add the
491 * property for the OS to enable storage D3, or allow it to be enabled by config.
492 */
493 if (config->is_storage
494 || (dev->sibling && (dev->sibling->class >> 16) == PCI_BASE_CLASS_STORAGE)) {
495 acpigen_write_device(acpi_device_name(dev));
496 acpigen_write_ADR(0);
497 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
Tim Wawrzynczak61083212021-08-05 09:40:19 -0600498 acpigen_write_name_integer("_S0W", ACPI_DEVICE_SLEEP_D3_COLD);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000499
500 dsd = acpi_dp_new_table("_DSD");
501 pkg = acpi_dp_new_table(PCIE_RTD3_STORAGE_UUID);
502 acpi_dp_add_integer(pkg, PCIE_RTD3_STORAGE_PROPERTY, 1);
503 acpi_dp_add_package(dsd, pkg);
504 acpi_dp_write(dsd);
505
506 acpigen_pop_len(); /* Device */
507
508 printk(BIOS_INFO, "%s: Added StorageD3Enable property\n", scope);
509 }
510
511 acpigen_pop_len(); /* Scope */
512}
513
514static const char *pcie_rtd3_acpi_name(const struct device *dev)
515{
516 /* Attached device name must be "PXSX" for the Linux Kernel to recognize it. */
517 return "PXSX";
518}
519
520static struct device_operations pcie_rtd3_ops = {
521 .read_resources = noop_read_resources,
522 .set_resources = noop_set_resources,
523 .acpi_fill_ssdt = pcie_rtd3_acpi_fill_ssdt,
524 .acpi_name = pcie_rtd3_acpi_name,
525};
526
527static void pcie_rtd3_acpi_enable(struct device *dev)
528{
529 dev->ops = &pcie_rtd3_ops;
530}
531
532struct chip_operations soc_intel_common_block_pcie_rtd3_ops = {
533 CHIP_NAME("Intel PCIe Runtime D3")
534 .enable_dev = pcie_rtd3_acpi_enable
535};