summaryrefslogtreecommitdiff
path: root/src/soc/intel/common/block/acpi/pep.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/soc/intel/common/block/acpi/pep.c')
-rw-r--r--src/soc/intel/common/block/acpi/pep.c87
1 files changed, 85 insertions, 2 deletions
diff --git a/src/soc/intel/common/block/acpi/pep.c b/src/soc/intel/common/block/acpi/pep.c
index 9b15bf3b32..b8e7e0d033 100644
--- a/src/soc/intel/common/block/acpi/pep.c
+++ b/src/soc/intel/common/block/acpi/pep.c
@@ -3,9 +3,12 @@
#include <acpi/acpigen.h>
#include <console/console.h>
#include <intelblocks/acpi.h>
+#include <intelblocks/pmc_ipc.h>
+#include <stdlib.h>
#include <types.h>
#define LPI_S0_HELPER_UUID "c4eb40a0-6cd2-11e2-bcfd-0800200c9a66"
+#define PEP_S0IX_UUID "57a6512e-3979-4e9d-9708-ff13b2508972"
#define SYSTEM_POWER_MANAGEMENT_HID "INT33A1"
#define SYSTEM_POWER_MANAGEMENT_CID "PNP0D80"
#define EC_S0IX_HOOK "\\_SB.PCI0.LPCB.EC0.S0IX"
@@ -16,6 +19,54 @@
#define MIN_DEVICE_STATE ACPI_DEVICE_SLEEP_D0
#define PEPD_SCOPE "\\_SB.PCI0"
+struct reg_info {
+ uint8_t *addr;
+ size_t buffer_size;
+};
+
+static void read_pmc_lpm_requirements(const struct soc_pmc_lpm *lpm,
+ struct reg_info *info)
+{
+ if (!CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_PEP_LPM_REQ) || !lpm) {
+ memset(info, 0, sizeof(*info));
+ return;
+ }
+
+ const size_t register_count = lpm->num_substates * lpm->num_req_regs;
+ uint32_t *reg = calloc(register_count, sizeof(uint32_t));
+
+ /* Read the various LPM state requirement registers from the PMC */
+ for (size_t i = 0; i < lpm->num_substates; i++) {
+ if (!(lpm->lpm_enable_mask & BIT(i)))
+ continue;
+
+ for (size_t j = 0; j < lpm->num_req_regs; j++) {
+ const uint32_t offset = lpm->lpm_ipc_offset +
+ i * lpm->req_reg_stride +
+ j * sizeof(uint32_t);
+ const uint32_t cmd_reg = pmc_make_ipc_cmd(PMC_IPC_CMD_RD_PMC_REG, 0, 0);
+ struct pmc_ipc_buffer req = {.buf[0] = offset};
+ struct pmc_ipc_buffer res = {};
+
+ enum cb_err result = pmc_send_ipc_cmd(cmd_reg, &req, &res);
+ if (result != CB_SUCCESS) {
+ printk(BIOS_ERR, "Failed to retrieve LPM substate registers"
+ "from LPM, substate %lu, reg %lu\n", i, j);
+ free(reg);
+ return;
+ }
+
+ uint32_t *ptr = reg + i * lpm->num_req_regs + j;
+ *ptr = res.buf[0];
+ }
+ }
+
+ if (info) {
+ info->addr = (uint8_t *)reg;
+ info->buffer_size = register_count * sizeof(uint32_t);
+ }
+}
+
/*
* For now there is only one disabled non-existent device, because Windows
* expects at least one device and crashes without it with a bluescreen
@@ -104,8 +155,31 @@ static void (*lpi_s0_helpers[])(void *) = {
lpi_s0ix_exit, /* s0ix exit */
};
-void generate_acpi_power_engine(void)
+static void pep_s0ix_return_lpm_requirements(void *arg)
+{
+ if (!CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_PEP_LPM_REQ)) {
+ acpigen_write_return_singleton_buffer(0x0);
+ return;
+ }
+
+ struct reg_info *info = (struct reg_info *)arg;
+ acpigen_write_return_byte_buffer(info->addr, info->buffer_size);
+}
+
+static void (*pep_s0ix[])(void *) = {
+ NULL, /* enumerate functions (autogenerated) */
+ pep_s0ix_return_lpm_requirements, /* Return LPM requirements */
+};
+
+void generate_acpi_power_engine_with_lpm(const struct soc_pmc_lpm *lpm)
{
+ struct reg_info info;
+ size_t uuid_count = 1;
+ struct dsm_uuid ids[] = {
+ DSM_UUID(LPI_S0_HELPER_UUID, lpi_s0_helpers, ARRAY_SIZE(lpi_s0_helpers), NULL),
+ DSM_UUID(PEP_S0IX_UUID, pep_s0ix, ARRAY_SIZE(pep_s0ix), &info),
+ };
+
acpigen_write_scope(PEPD_SCOPE);
acpigen_write_device("PEPD");
@@ -113,10 +187,19 @@ void generate_acpi_power_engine(void)
acpigen_write_name("_CID");
acpigen_emit_eisaid(SYSTEM_POWER_MANAGEMENT_CID);
- acpigen_write_dsm(LPI_S0_HELPER_UUID, lpi_s0_helpers, ARRAY_SIZE(lpi_s0_helpers), NULL);
+ read_pmc_lpm_requirements(lpm, &info);
+ if (info.buffer_size)
+ uuid_count++;
+ acpigen_write_dsm_uuid_arr(ids, uuid_count);
acpigen_write_device_end();
acpigen_write_scope_end();
+ free(info.addr);
printk(BIOS_INFO, PEPD_SCOPE ".PEPD: Intel Power Engine Plug-in\n");
}
+
+void generate_acpi_power_engine(void)
+{
+ generate_acpi_power_engine_with_lpm(NULL);
+}