blob: 9b15bf3b3204142d51d935555f55ff8a179e9909 [file] [log] [blame]
Tim Wawrzynczak64246482021-06-25 22:44:45 -06001/* SPDX-License-Identifier: GPL-2.0-or-later */
2
3#include <acpi/acpigen.h>
4#include <console/console.h>
5#include <intelblocks/acpi.h>
6#include <types.h>
7
8#define LPI_S0_HELPER_UUID "c4eb40a0-6cd2-11e2-bcfd-0800200c9a66"
9#define SYSTEM_POWER_MANAGEMENT_HID "INT33A1"
10#define SYSTEM_POWER_MANAGEMENT_CID "PNP0D80"
11#define EC_S0IX_HOOK "\\_SB.PCI0.LPCB.EC0.S0IX"
12#define MAINBOARD_HOOK "\\_SB.MS0X"
13#define ENABLE_PM_BITS_HOOK "\\_SB.PCI0.EGPM"
14#define RESTORE_PM_BITS_HOOK "\\_SB.PCI0.RGPM"
15#define LPI_STATES_ALL 0xff
16#define MIN_DEVICE_STATE ACPI_DEVICE_SLEEP_D0
17#define PEPD_SCOPE "\\_SB.PCI0"
18
19/*
20 * For now there is only one disabled non-existent device, because Windows
21 * expects at least one device and crashes without it with a bluescreen
22 * (`INTERNAL_POWER_ERROR`). Returning an empty package does not work.
23 */
24static void lpi_get_constraints(void *unused)
25{
26 /*
27 * Return (Package() {
28 * Package() { "\NULL", 0,
29 * Package() { 0,
30 * Package() { 0xff, 0 }}}})
31 */
32 acpigen_emit_byte(RETURN_OP);
33 acpigen_write_package(1);
34 {
35 acpigen_write_package(3);
36 {
37 acpigen_emit_namestring("\\NULL");
38 acpigen_write_integer(0); /* device disabled */
39 acpigen_write_package(2);
40 {
41 acpigen_write_integer(0); /* revision */
42 acpigen_write_package(2);
43 {
44 acpigen_write_integer(LPI_STATES_ALL);
45 acpigen_write_integer(MIN_DEVICE_STATE);
46 }
47 acpigen_write_package_end();
48 }
49 acpigen_write_package_end();
50 }
51 acpigen_write_package_end();
52 }
53 acpigen_write_package_end();
54}
55
56static void lpi_s0ix_entry(void *unused)
57{
58 /* Inform the EC */
59 acpigen_write_if_cond_ref_of(EC_S0IX_HOOK);
60 acpigen_emit_namestring(EC_S0IX_HOOK);
61 acpigen_write_integer(1);
62 acpigen_write_if_end();
63
64 /* Provide a board level S0ix hook */
65 acpigen_write_if_cond_ref_of(MAINBOARD_HOOK);
66 acpigen_emit_namestring(MAINBOARD_HOOK);
67 acpigen_write_integer(1);
68 acpigen_write_if_end();
69
70 /* Save the current PM bits then enable GPIO PM with
71 MISCCFG_GPIO_PM_CONFIG_BITS */
72 acpigen_write_if_cond_ref_of(ENABLE_PM_BITS_HOOK);
73 acpigen_emit_namestring(ENABLE_PM_BITS_HOOK);
74 acpigen_write_if_end();
75}
76
77static void lpi_s0ix_exit(void *unused)
78{
79 /* Inform the EC */
80 acpigen_write_if_cond_ref_of(EC_S0IX_HOOK);
81 acpigen_emit_namestring(EC_S0IX_HOOK);
82 acpigen_write_integer(0);
83 acpigen_write_if_end();
84
85 /* Provide a board level S0ix hook */
86 acpigen_write_if_cond_ref_of(MAINBOARD_HOOK);
87 acpigen_emit_namestring(MAINBOARD_HOOK);
88 acpigen_write_integer(0);
89 acpigen_write_if_end();
90
91 /* Restore GPIO all Community PM */
92 acpigen_write_if_cond_ref_of(RESTORE_PM_BITS_HOOK);
93 acpigen_emit_namestring(RESTORE_PM_BITS_HOOK);
94 acpigen_write_if_end();
95}
96
97static void (*lpi_s0_helpers[])(void *) = {
98 NULL, /* enumerate functions (autogenerated) */
99 lpi_get_constraints, /* get device constraints */
100 NULL, /* get crash dump device */
101 NULL, /* display off notify */
102 NULL, /* display on notify */
103 lpi_s0ix_entry, /* s0ix entry */
104 lpi_s0ix_exit, /* s0ix exit */
105};
106
107void generate_acpi_power_engine(void)
108{
109 acpigen_write_scope(PEPD_SCOPE);
110 acpigen_write_device("PEPD");
111
112 acpigen_write_name_string("_HID", SYSTEM_POWER_MANAGEMENT_HID);
113 acpigen_write_name("_CID");
114 acpigen_emit_eisaid(SYSTEM_POWER_MANAGEMENT_CID);
115
116 acpigen_write_dsm(LPI_S0_HELPER_UUID, lpi_s0_helpers, ARRAY_SIZE(lpi_s0_helpers), NULL);
117
118 acpigen_write_device_end();
119 acpigen_write_scope_end();
120
121 printk(BIOS_INFO, PEPD_SCOPE ".PEPD: Intel Power Engine Plug-in\n");
122}