static int smm_handler_copied = 0;
+static int is_wakeup(void)
+{
+ device_t dev0 = dev_find_slot(0, PCI_DEVFN(0,0));
+
+ if (!dev0)
+ return 0;
+
+ return pci_read_config32(dev0, 0xdc) == SKPAD_ACPI_S3_MAGIC;
+}
+
static void smm_install(void)
{
/* The first CPU running this gets to copy the SMM handler. But not all
return;
smm_handler_copied = 1;
- /* enable the SMM memory window */
- pci_write_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), SMRAM,
- D_OPEN | G_SMRAME | C_BASE_SEG);
- /* copy the real SMM handler */
- memcpy((void *)0xa0000, &_binary_smm_start, (size_t)&_binary_smm_size);
- wbinvd();
+ /* if we're resuming from S3, the SMM code is already in place,
+ * so don't copy it again to keep the current SMM state */
+
+ if (!is_wakeup()) {
+ /* enable the SMM memory window */
+ pci_write_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), SMRAM,
+ D_OPEN | G_SMRAME | C_BASE_SEG);
+
+ /* copy the real SMM handler */
+ memcpy((void *)0xa0000, &_binary_smm_start, (size_t)&_binary_smm_size);
+ wbinvd();
+ }
/* close the SMM memory window and enable normal SMM */
pci_write_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), SMRAM,
default: printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); break;
}
+ /* Unlock the SMI semaphore. We're currently in SMM, and the semaphore
+ * will never be unlocked because the next outl will switch off the CPU.
+ * This might open a small race between the smi_release_lock() and the outl()
+ * for other SMI handlers. Not sure if this could cause trouble. */
+ if (slp_typ == 5)
+ smi_release_lock();
+
/* Write back to the SLP register to cause the originally intended
* event again. We need to set BIT13 (SLP_EN) though to make the
* sleep happen.