arch/x86: Create helper for APM_CNT SMI triggers

Attempts to write to APM_CNT IO port should always be guarded
with a test to verify SMI handler has been installed.

Immediate followup removes redundant HAVE_SMI_HANDLER tests.

Change-Id: If3fb0f1a8b32076f1d9f3fea9f817dd4b093ad98
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41971
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Patrick Rudolph <siro@das-labor.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Kyösti Mälkki 2020-06-01 15:11:14 +03:00 committed by Patrick Georgi
parent 9446447475
commit b6585481e8
18 changed files with 68 additions and 53 deletions

View File

@ -1,6 +1,7 @@
## SPDX-License-Identifier: GPL-2.0-only ## SPDX-License-Identifier: GPL-2.0-only
ramstage-y += smm_module_loader.c ramstage-y += smm_module_loader.c
ramstage-y += smi_trigger.c
ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_32),y) ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_32),y)
$(eval $(call create_class_compiler,smm,x86_32)) $(eval $(call create_class_compiler,smm,x86_32))

View File

@ -0,0 +1,43 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <arch/io.h>
#include <console/console.h>
#include <cpu/x86/smm.h>
int apm_control(u8 cmd)
{
if (!CONFIG(HAVE_SMI_HANDLER))
return -1;
switch (cmd) {
case APM_CNT_CST_CONTROL:
break;
case APM_CNT_PST_CONTROL:
break;
case APM_CNT_ACPI_DISABLE:
printk(BIOS_DEBUG, "Disabling ACPI via APMC.\n");
break;
case APM_CNT_ACPI_ENABLE:
printk(BIOS_DEBUG, "Enabling ACPI via APMC.\n");
break;
case APM_CNT_GNVS_UPDATE:
break;
case APM_CNT_FINALIZE:
printk(BIOS_DEBUG, "Finalizing SMM.\n");
break;
case APM_CNT_ELOG_GSMI:
break;
case APM_CNT_SMMSTORE:
break;
case APM_CNT_SMMINFO:
break;
default:
break;
}
/* Now raise the SMI. */
outb(cmd, APM_CNT);
printk(BIOS_DEBUG, "APMC done.\n");
return 0;
}

View File

@ -29,6 +29,9 @@
#define APM_CNT_ELOG_GSMI 0xef #define APM_CNT_ELOG_GSMI 0xef
#define APM_STS 0xb3 #define APM_STS 0xb3
/* Send cmd to APM_CNT with HAVE_SMI_HANDLER checking. */
int apm_control(u8 cmd);
void io_trap_handler(int smif); void io_trap_handler(int smif);
int southbridge_io_trap_handler(int smif); int southbridge_io_trap_handler(int smif);
int mainboard_io_trap_handler(int smif); int mainboard_io_trap_handler(int smif);

View File

@ -410,9 +410,7 @@ static void pch_cg_init(struct device *dev)
static void pch_set_acpi_mode(void) static void pch_set_acpi_mode(void)
{ {
if (CONFIG(HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) { if (CONFIG(HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) {
printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); apm_control(APM_CNT_ACPI_DISABLE);
outb(APM_CNT_ACPI_DISABLE, APM_CNT);
printk(BIOS_DEBUG, "done.\n");
} }
} }

View File

@ -101,9 +101,7 @@ static void soc_finalize(void *unused)
printk(BIOS_DEBUG, "Finalizing chipset.\n"); printk(BIOS_DEBUG, "Finalizing chipset.\n");
pch_finalize(); pch_finalize();
apm_control(APM_CNT_FINALIZE);
printk(BIOS_DEBUG, "Finalizing SMM.\n");
outb(APM_CNT_FINALIZE, APM_CNT);
/* Indicate finalize step with post code */ /* Indicate finalize step with post code */
post_code(POST_OS_BOOT); post_code(POST_OS_BOOT);

View File

@ -94,9 +94,7 @@ static void pch_pmc_read_resources(struct device *dev)
void pmc_set_acpi_mode(void) void pmc_set_acpi_mode(void)
{ {
if (CONFIG(HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) { if (CONFIG(HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) {
printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); apm_control(APM_CNT_ACPI_DISABLE);
outb(APM_CNT_ACPI_DISABLE, APM_CNT);
printk(BIOS_DEBUG, "done.\n");
} }
} }

View File

@ -555,8 +555,7 @@ static const struct pci_driver lpc_driver __pci_driver = {
static void finalize_chipset(void *unused) static void finalize_chipset(void *unused)
{ {
printk(BIOS_DEBUG, "Finalizing SMM.\n"); apm_control(APM_CNT_FINALIZE);
outb(APM_CNT_FINALIZE, APM_CNT);
} }
BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, finalize_chipset, NULL); BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, finalize_chipset, NULL);

View File

@ -25,9 +25,7 @@ static void pch_power_options(struct device *dev) { /* TODO */ }
static void pch_set_acpi_mode(void) static void pch_set_acpi_mode(void)
{ {
if (CONFIG(HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) { if (CONFIG(HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) {
printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); apm_control(APM_CNT_ACPI_DISABLE);
outb(APM_CNT_ACPI_DISABLE, APM_CNT);
printk(BIOS_DEBUG, "done.\n");
} }
} }

View File

@ -94,9 +94,7 @@ static void soc_finalize(void *unused)
printk(BIOS_DEBUG, "Finalizing chipset.\n"); printk(BIOS_DEBUG, "Finalizing chipset.\n");
pch_finalize(); pch_finalize();
apm_control(APM_CNT_FINALIZE);
printk(BIOS_DEBUG, "Finalizing SMM.\n");
outb(APM_CNT_FINALIZE, APM_CNT);
/* Indicate finalize step with post code */ /* Indicate finalize step with post code */
post_code(POST_OS_BOOT); post_code(POST_OS_BOOT);

View File

@ -87,9 +87,7 @@ static void soc_finalize(void *unused)
printk(BIOS_DEBUG, "Finalizing chipset.\n"); printk(BIOS_DEBUG, "Finalizing chipset.\n");
pch_finalize(); pch_finalize();
apm_control(APM_CNT_FINALIZE);
printk(BIOS_DEBUG, "Finalizing SMM.\n");
outb(APM_CNT_FINALIZE, APM_CNT);
/* Indicate finalize step with post code */ /* Indicate finalize step with post code */
post_code(POST_OS_BOOT); post_code(POST_OS_BOOT);

View File

@ -128,9 +128,7 @@ static void soc_finalize(void *unused)
pch_finalize_script(dev); pch_finalize_script(dev);
soc_lockdown(dev); soc_lockdown(dev);
apm_control(APM_CNT_FINALIZE);
printk(BIOS_DEBUG, "Finalizing SMM.\n");
outb(APM_CNT_FINALIZE, APM_CNT);
/* Indicate finalize step with post code */ /* Indicate finalize step with post code */
post_code(POST_OS_BOOT); post_code(POST_OS_BOOT);

View File

@ -73,9 +73,7 @@ static void soc_finalize(void *unused)
printk(BIOS_DEBUG, "Finalizing chipset.\n"); printk(BIOS_DEBUG, "Finalizing chipset.\n");
pch_finalize(); pch_finalize();
apm_control(APM_CNT_FINALIZE);
printk(BIOS_DEBUG, "Finalizing SMM.\n");
outb(APM_CNT_FINALIZE, APM_CNT);
/* Indicate finalize step with post code */ /* Indicate finalize step with post code */
post_code(POST_OS_BOOT); post_code(POST_OS_BOOT);

View File

@ -405,9 +405,7 @@ static void enable_clock_gating(struct device *dev)
static void pch_set_acpi_mode(void) static void pch_set_acpi_mode(void)
{ {
if (!acpi_is_wakeup_s3() && CONFIG(HAVE_SMI_HANDLER)) { if (!acpi_is_wakeup_s3() && CONFIG(HAVE_SMI_HANDLER)) {
printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); apm_control(APM_CNT_ACPI_DISABLE);
outb(APM_CNT_ACPI_DISABLE, APM_CNT); // Disable ACPI mode
printk(BIOS_DEBUG, "done.\n");
} }
} }
@ -827,7 +825,7 @@ static void lpc_final(struct device *dev)
if (CONFIG(HAVE_SMI_HANDLER)) { if (CONFIG(HAVE_SMI_HANDLER)) {
if (CONFIG(INTEL_CHIPSET_LOCKDOWN) || if (CONFIG(INTEL_CHIPSET_LOCKDOWN) ||
acpi_is_wakeup_s3()) { acpi_is_wakeup_s3()) {
outb(APM_CNT_FINALIZE, APM_CNT); apm_control(APM_CNT_FINALIZE);
} }
} }
} }

View File

@ -316,12 +316,9 @@ static void i82801gx_set_acpi_mode(struct device *dev)
{ {
if (CONFIG(HAVE_SMI_HANDLER)) { if (CONFIG(HAVE_SMI_HANDLER)) {
if (!acpi_is_wakeup_s3()) { if (!acpi_is_wakeup_s3()) {
printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); apm_control(APM_CNT_ACPI_DISABLE);
outb(APM_CNT_ACPI_DISABLE, APM_CNT); // Disable ACPI mode
printk(BIOS_DEBUG, "done.\n");
} else { } else {
printk(BIOS_DEBUG, "S3 wakeup, enabling ACPI via APMC\n"); apm_control(APM_CNT_ACPI_ENABLE);
outb(APM_CNT_ACPI_ENABLE, APM_CNT);
} }
} }
} }

View File

@ -345,12 +345,9 @@ static void i82801ix_set_acpi_mode(struct device *dev)
{ {
if (CONFIG(HAVE_SMI_HANDLER)) { if (CONFIG(HAVE_SMI_HANDLER)) {
if (!acpi_is_wakeup_s3()) { if (!acpi_is_wakeup_s3()) {
printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); apm_control(APM_CNT_ACPI_DISABLE);
outb(APM_CNT_ACPI_DISABLE, APM_CNT); // Disable ACPI mode
printk(BIOS_DEBUG, "done.\n");
} else { } else {
printk(BIOS_DEBUG, "S3 wakeup, enabling ACPI via APMC\n"); apm_control(APM_CNT_ACPI_ENABLE);
outb(APM_CNT_ACPI_ENABLE, APM_CNT);
} }
} }
} }

View File

@ -349,12 +349,9 @@ static void i82801jx_set_acpi_mode(struct device *dev)
{ {
if (CONFIG(HAVE_SMI_HANDLER)) { if (CONFIG(HAVE_SMI_HANDLER)) {
if (!acpi_is_wakeup_s3()) { if (!acpi_is_wakeup_s3()) {
printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); apm_control(APM_CNT_ACPI_DISABLE);
outb(APM_CNT_ACPI_DISABLE, APM_CNT); // Disable ACPI mode
printk(BIOS_DEBUG, "done.\n");
} else { } else {
printk(BIOS_DEBUG, "S3 wakeup, enabling ACPI via APMC\n"); apm_control(APM_CNT_ACPI_ENABLE);
outb(APM_CNT_ACPI_ENABLE, APM_CNT);
} }
} }
} }

View File

@ -409,9 +409,7 @@ static void enable_clock_gating(struct device *dev)
static void pch_set_acpi_mode(void) static void pch_set_acpi_mode(void)
{ {
if (!acpi_is_wakeup_s3() && CONFIG(HAVE_SMI_HANDLER)) { if (!acpi_is_wakeup_s3() && CONFIG(HAVE_SMI_HANDLER)) {
printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); apm_control(APM_CNT_ACPI_DISABLE); // Disable ACPI mode
outb(APM_CNT_ACPI_DISABLE, APM_CNT); // Disable ACPI mode
printk(BIOS_DEBUG, "done.\n");
} }
} }
@ -727,7 +725,7 @@ static void lpc_final(struct device *dev)
if (CONFIG(HAVE_SMI_HANDLER)) { if (CONFIG(HAVE_SMI_HANDLER)) {
if (CONFIG(INTEL_CHIPSET_LOCKDOWN) || if (CONFIG(INTEL_CHIPSET_LOCKDOWN) ||
acpi_is_wakeup_s3()) { acpi_is_wakeup_s3()) {
outb(APM_CNT_FINALIZE, APM_CNT); apm_control(APM_CNT_FINALIZE);
} }
} }
} }

View File

@ -474,9 +474,7 @@ static void enable_lp_clock_gating(struct device *dev)
static void pch_set_acpi_mode(void) static void pch_set_acpi_mode(void)
{ {
if (CONFIG(HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) { if (CONFIG(HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) {
printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); apm_control(APM_CNT_ACPI_DISABLE);
outb(APM_CNT_ACPI_DISABLE, APM_CNT);
printk(BIOS_DEBUG, "done.\n");
} }
} }
@ -923,7 +921,7 @@ static void lpc_final(struct device *dev)
spi_finalize_ops(); spi_finalize_ops();
if (acpi_is_wakeup_s3() || CONFIG(INTEL_CHIPSET_LOCKDOWN)) if (acpi_is_wakeup_s3() || CONFIG(INTEL_CHIPSET_LOCKDOWN))
outb(APM_CNT_FINALIZE, APM_CNT); apm_control(APM_CNT_FINALIZE);
} }
static struct device_operations device_ops = { static struct device_operations device_ops = {