blob: 6eb647119cb5808148ae131d88cc18c0fa256fa4 [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);
Cliff Huang9a5a9632023-01-24 17:05:17 -0800263 /*
264 * Depending on the board configuration we use either the "enable" or
265 * the "reset" pin to detect the status of the device. The logic for
266 * each pin is detailed below.
267 *
268 * 1. For the "enable" pin:
269 * | polarity | tx value | get_tx_gpio() | State |
270 * |-------------+----------+---------------+-------|
271 * | active high | 0 | 0 | 0 |
272 * | active high | 1 | 1(active) | 1 |
273 * | active low | 0 | 1(active) | 1 |
274 * | active low | 1 | 0 | 0 |
275 *
276 * 2. For the "reset" pin:
277 * | polarity | tx value | get_tx_gpio() | State |
278 * |-------------+----------+---------------+-------|
279 * | active high | 0 | 0 | 1 |
280 * | active high | 1 | 1(active) | 0 |
281 * | active low | 0 | 1(active) | 0 |
282 * | active low | 1 | 0 | 1 |
283 */
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000284
285 /* Use enable GPIO for status if provided, otherwise use reset GPIO. */
Cliff Huang9a5a9632023-01-24 17:05:17 -0800286 if (config->enable_gpio.pin_count) {
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000287 gpio = &config->enable_gpio;
Cliff Huang9a5a9632023-01-24 17:05:17 -0800288 /* Read current GPIO state into Local0. */
289 acpigen_get_tx_gpio(gpio);
290 } else {
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000291 gpio = &config->reset_gpio;
Cliff Huang9a5a9632023-01-24 17:05:17 -0800292 /* Read current GPIO state into Local0. */
293 acpigen_get_tx_gpio(gpio);
294 acpigen_write_not(LOCAL0_OP, LOCAL0_OP);
295 }
296 acpigen_write_return_op(LOCAL0_OP);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000297 acpigen_pop_len(); /* Method */
298}
299
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700300static void write_modphy_opregion(unsigned int pcie_rp)
301{
302 /* The register containing the Power Gate enable sequence bits is at
303 PCH_PWRM_BASE + 0x10D0, and the bits to check for sequence completion are at
304 PCH_PWRM_BASE + 0x10D4. */
305 const struct opregion opregion = OPREGION("PMCP", SYSTEMMEMORY,
306 PCH_PWRM_BASE_ADDRESS + 0x1000, 0xff);
307 const struct fieldlist fieldlist[] = {
308 FIELDLIST_OFFSET(0xD0),
309 FIELDLIST_RESERVED(pcie_rp),
310 FIELDLIST_NAMESTR("EMPG", 1), /* Enable ModPHY Power Gate */
311 FIELDLIST_OFFSET(0xD4),
312 FIELDLIST_RESERVED(pcie_rp),
313 FIELDLIST_NAMESTR("AMPG", 1), /* Is ModPHY Power Gate active? */
314 };
315
316 acpigen_write_opregion(&opregion);
317 acpigen_write_field("PMCP", fieldlist, ARRAY_SIZE(fieldlist),
318 FIELD_DWORDACC | FIELD_NOLOCK | FIELD_PRESERVE);
319}
320
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700321static int get_pcie_rp_pmc_idx(enum pcie_rp_type rp_type, const struct device *dev)
322{
323 int idx = -1;
324
325 switch (rp_type) {
326 case PCIE_RP_PCH:
327 /* Read port number of root port that this device is attached to. */
328 idx = pci_read_config8(dev, PCH_PCIE_CFG_LCAP_PN);
329
330 /* Port number is 1-based, PMC IPC method expects 0-based. */
331 idx--;
332 break;
333 case PCIE_RP_CPU:
334 /* CPU RPs are indexed by their "virtual wire index" to the PCH */
335 idx = soc_get_cpu_rp_vw_idx(dev);
336 break;
337 default:
338 break;
339 }
340
341 return idx;
342}
343
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000344static void pcie_rtd3_acpi_fill_ssdt(const struct device *dev)
345{
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700346 static bool mutex_created = false;
347
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000348 const struct soc_intel_common_block_pcie_rtd3_config *config = config_of(dev);
349 static const char *const power_res_states[] = {"_PR0"};
350 const struct device *parent = dev->bus->dev;
351 const char *scope = acpi_device_path(parent);
352 const struct opregion opregion = OPREGION("PXCS", PCI_CONFIG, 0, 0xff);
353 const struct fieldlist fieldlist[] = {
354 FIELDLIST_OFFSET(PCH_PCIE_CFG_LSTS),
355 FIELDLIST_RESERVED(13),
356 FIELDLIST_NAMESTR(ACPI_REG_PCI_LINK_ACTIVE, 1),
357 FIELDLIST_OFFSET(PCH_PCIE_CFG_SPR),
358 FIELDLIST_RESERVED(7),
359 FIELDLIST_NAMESTR(ACPI_REG_PCI_L23_SAVE_STATE, 1),
360 FIELDLIST_OFFSET(PCH_PCIE_CFG_RPPGEN),
361 FIELDLIST_RESERVED(2),
362 FIELDLIST_NAMESTR(ACPI_REG_PCI_L23_RDY_ENTRY, 1),
363 FIELDLIST_NAMESTR(ACPI_REG_PCI_L23_RDY_DETECT, 1),
364 };
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700365 int pcie_rp;
Kapil Porwal65bcb572022-11-28 18:53:40 +0530366 struct acpi_dp *dsd;
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000367
368 if (!is_dev_enabled(parent)) {
369 printk(BIOS_ERR, "%s: root port not enabled\n", __func__);
370 return;
371 }
372 if (!scope) {
373 printk(BIOS_ERR, "%s: root port scope not found\n", __func__);
374 return;
375 }
376 if (!config->enable_gpio.pin_count && !config->reset_gpio.pin_count) {
377 printk(BIOS_ERR, "%s: Enable and/or Reset GPIO required for %s.\n",
378 __func__, scope);
379 return;
380 }
Rizwan Qureshia9794602021-04-08 20:31:47 +0530381 if (config->srcclk_pin > CONFIG_MAX_PCIE_CLOCK_SRC) {
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000382 printk(BIOS_ERR, "%s: Invalid clock pin %u for %s.\n", __func__,
383 config->srcclk_pin, scope);
384 return;
385 }
386
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700387 const enum pcie_rp_type rp_type = soc_get_pcie_rp_type(parent);
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700388 pcie_rp = get_pcie_rp_pmc_idx(rp_type, parent);
Tim Wawrzynczakb3cd55b2022-01-20 14:06:29 -0700389 if (pcie_rp < 0) {
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700390 printk(BIOS_ERR, "%s: Unknown PCIe root port\n", __func__);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000391 return;
392 }
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800393 if (config->disable_l23) {
Angel Ponsd85319a2022-02-13 13:35:20 +0100394 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_L23) {
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800395 printk(BIOS_ERR, "%s: Can not export L23 methods\n", __func__);
396 return;
397 }
398 }
399 if (rp_type != PCIE_RP_PCH) {
Angel Ponsd85319a2022-02-13 13:35:20 +0100400 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_PSD0) {
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800401 printk(BIOS_ERR, "%s: Can not export PSD0 method\n", __func__);
402 return;
403 }
404 }
405 if (config->srcclk_pin == 0) {
Angel Ponsd85319a2022-02-13 13:35:20 +0100406 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_SRCK) {
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800407 printk(BIOS_ERR, "%s: Can not export SRCK method\n", __func__);
408 return;
409 }
410 }
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000411
412 printk(BIOS_INFO, "%s: Enable RTD3 for %s (%s)\n", scope, dev_path(parent),
413 config->desc ?: dev->chip_ops->name);
414
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700415 /* Create a mutex for exclusive access to the PMC registers. */
416 if (rp_type == PCIE_RP_PCH && !mutex_created) {
417 acpigen_write_scope("\\_SB.PCI0");
418 acpigen_write_mutex("R3MX", 0);
419 acpigen_write_scope_end();
420 mutex_created = true;
421 }
422
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000423 /* The RTD3 power resource is added to the root port, not the device. */
424 acpigen_write_scope(scope);
425
426 if (config->desc)
427 acpigen_write_name_string("_DDN", config->desc);
428
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700429 /* Create OpRegions for MMIO accesses. */
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000430 acpigen_write_opregion(&opregion);
431 acpigen_write_field("PXCS", fieldlist, ARRAY_SIZE(fieldlist),
432 FIELD_ANYACC | FIELD_NOLOCK | FIELD_PRESERVE);
433
Angel Ponsd85319a2022-02-13 13:35:20 +0100434 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_L23) {
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800435 pcie_rtd3_acpi_method_dl23();
436 pcie_rtd3_acpi_method_l23d();
437 }
438
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700439 /* Create the OpRegion to access the ModPHY PG registers (PCH RPs only) */
440 if (rp_type == PCIE_RP_PCH)
441 write_modphy_opregion(pcie_rp);
442
Angel Ponsd85319a2022-02-13 13:35:20 +0100443 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_PSD0)
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800444 pcie_rtd3_acpi_method_pds0(pcie_rp);
445
Angel Ponsd85319a2022-02-13 13:35:20 +0100446 if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_SRCK)
Cliff Huang4bc9ac72022-01-21 00:23:15 -0800447 pcie_rtd3_acpi_method_srck(pcie_rp, config);
448
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000449 /* ACPI Power Resource for controlling the attached device power. */
450 acpigen_write_power_res("RTD3", 0, 0, power_res_states, ARRAY_SIZE(power_res_states));
Cliff Huangd1a74162022-01-21 14:54:32 -0800451
452 if (config->skip_on_off_support) {
453 /* OFSK: 0 = _OFF Method will be executed normally when called;
454 * >1 = _OFF will be skipped.
455 * _OFF Method to decrement OFSK and increment ONSK if the
456 * current execution is skipped.
457 * ONSK: 0 = _ON Method will be executed normally when called;
458 * >1 = _ONF will be skipped.
459 * _ON Method to decrement ONSK if the current execution is
460 * skipped.
461 */
462 acpigen_write_name_integer("ONSK", 0);
463 acpigen_write_name_integer("OFSK", 0);
464 }
465
Tim Wawrzynczakb6a15a72021-12-08 10:43:56 -0700466 pcie_rtd3_acpi_method_status(config);
Kane Chen11be5562022-11-03 23:18:44 +0800467 pcie_rtd3_acpi_method_on(pcie_rp, config, rp_type, dev);
Tim Wawrzynczak32f883e2021-12-02 16:19:47 -0700468 pcie_rtd3_acpi_method_off(pcie_rp, config, rp_type);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000469 acpigen_pop_len(); /* PowerResource */
470
471 /* Indicate to the OS that device supports hotplug in D3. */
472 dsd = acpi_dp_new_table("_DSD");
Kapil Porwal65bcb572022-11-28 18:53:40 +0530473 acpi_device_add_hotplug_support_in_d3(dsd);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000474
475 /* Indicate to the OS if the device provides an External facing port. */
Kapil Porwal65bcb572022-11-28 18:53:40 +0530476 if (config->add_acpi_external_facing_port)
477 acpi_device_add_external_facing_port(dsd);
Kapil Porwald7eacd72022-11-28 11:03:38 +0530478
479 /* Indicate to the OS if the device has DMA property. */
480 if (config->add_acpi_dma_property)
481 acpi_device_add_dma_property(dsd);
482
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000483 acpi_dp_write(dsd);
484
485 /*
486 * Check the sibling device on the root port to see if it is storage class and add the
487 * property for the OS to enable storage D3, or allow it to be enabled by config.
488 */
489 if (config->is_storage
490 || (dev->sibling && (dev->sibling->class >> 16) == PCI_BASE_CLASS_STORAGE)) {
491 acpigen_write_device(acpi_device_name(dev));
492 acpigen_write_ADR(0);
493 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
Tim Wawrzynczak61083212021-08-05 09:40:19 -0600494 acpigen_write_name_integer("_S0W", ACPI_DEVICE_SLEEP_D3_COLD);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000495
Kapil Porwal65bcb572022-11-28 18:53:40 +0530496 acpi_device_add_storage_d3_enable(NULL);
Duncan Laurie64bc26a2020-10-10 00:15:28 +0000497
498 acpigen_pop_len(); /* Device */
499
500 printk(BIOS_INFO, "%s: Added StorageD3Enable property\n", scope);
501 }
502
503 acpigen_pop_len(); /* Scope */
504}
505
506static const char *pcie_rtd3_acpi_name(const struct device *dev)
507{
508 /* Attached device name must be "PXSX" for the Linux Kernel to recognize it. */
509 return "PXSX";
510}
511
512static struct device_operations pcie_rtd3_ops = {
513 .read_resources = noop_read_resources,
514 .set_resources = noop_set_resources,
515 .acpi_fill_ssdt = pcie_rtd3_acpi_fill_ssdt,
516 .acpi_name = pcie_rtd3_acpi_name,
517};
518
519static void pcie_rtd3_acpi_enable(struct device *dev)
520{
521 dev->ops = &pcie_rtd3_ops;
522}
523
524struct chip_operations soc_intel_common_block_pcie_rtd3_ops = {
525 CHIP_NAME("Intel PCIe Runtime D3")
526 .enable_dev = pcie_rtd3_acpi_enable
527};