Add TPM support to coreboot
[coreboot.git] / src / arch / x86 / boot / acpi.c
index 957ec4559a0459b763f1c563200c70d9b0eef6d4..33d730bc8c2f0eb90d5ade3c9781f9993b29a287 100644 (file)
 #include <arch/acpigen.h>
 #include <device/pci.h>
 #include <cbmem.h>
+#include <cpu/x86/lapic_def.h>
+#if CONFIG_CHROMEOS
+#include <vendorcode/google/chromeos/chromeos.h>
+#endif
 
 u8 acpi_checksum(u8 *table, u32 length)
 {
@@ -69,7 +73,7 @@ void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
 
        if (i >= entries_num) {
                printk(BIOS_ERR, "ACPI: Error: Could not add ACPI table, "
-                      "too many tables.\n");
+                       "too many tables.\n");
                return;
        }
 
@@ -93,20 +97,20 @@ void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
 
                /* Fix XSDT length. */
                xsdt->header.length = sizeof(acpi_header_t) +
-                                     (sizeof(u64) * (i + 1));
+                                       (sizeof(u64) * (i + 1));
 
                /* Re-calculate checksum. */
                xsdt->header.checksum = 0;
                xsdt->header.checksum = acpi_checksum((u8 *)xsdt,
-                                                     xsdt->header.length);
+                                                       xsdt->header.length);
        }
 
        printk(BIOS_DEBUG, "ACPI: added table %d/%d, length now %d\n",
-              i + 1, entries_num, rsdt->header.length);
+               i + 1, entries_num, rsdt->header.length);
 }
 
 int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base,
-                             u16 seg_nr, u8 start, u8 end)
+                               u16 seg_nr, u8 start, u8 end)
 {
        mmconfig->base_address = base;
        mmconfig->base_reserved = 0;
@@ -135,7 +139,7 @@ unsigned long acpi_create_madt_lapics(unsigned long current)
 
        for (cpu = all_devices; cpu; cpu = cpu->next) {
                if ((cpu->path.type != DEVICE_PATH_APIC) ||
-                  (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER)) {
+                       (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER)) {
                        continue;
                }
                if (!cpu->enabled)
@@ -149,7 +153,7 @@ unsigned long acpi_create_madt_lapics(unsigned long current)
 }
 
 int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,
-                           u32 gsi_base)
+                               u32 gsi_base)
 {
        ioapic->type = 1; /* I/O APIC structure */
        ioapic->length = sizeof(acpi_madt_ioapic_t);
@@ -175,7 +179,7 @@ int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
 }
 
 int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
-                              u16 flags, u8 lint)
+                               u16 flags, u8 lint)
 {
        lapic_nmi->type = 4; /* Local APIC NMI structure */
        lapic_nmi->length = sizeof(acpi_madt_lapic_nmi_t);
@@ -188,8 +192,6 @@ int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
 
 void acpi_create_madt(acpi_madt_t *madt)
 {
-#define LOCAL_APIC_ADDR        0xfee00000ULL
-
        acpi_header_t *header = &(madt->header);
        unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t);
 
@@ -287,7 +289,7 @@ int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
 }
 
 int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
-                        u32 flags)
+                               u32 flags)
 {
        mem->type = 1; /* Memory affinity structure */
        mem->length = sizeof(acpi_srat_mem_t);
@@ -481,7 +483,8 @@ u8 acpi_slp_type = 0;
 
 static int acpi_is_wakeup(void)
 {
-       return (acpi_slp_type == 3);
+       /* Both resume from S2 and resume from S3 restart at CPU reset */
+       return (acpi_slp_type == 3 || acpi_slp_type == 2);
 }
 
 static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
@@ -524,6 +527,11 @@ void *acpi_find_wakeup_vector(void)
        if (!acpi_is_wakeup())
                return NULL;
 
+#if CONFIG_CHROMEOS
+       printk(BIOS_DEBUG, "Verified boot TPM initialization.\n");
+       init_vboot();
+#endif
+
        printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n");
 
        /* Find RSDP. */
@@ -567,9 +575,11 @@ void *acpi_find_wakeup_vector(void)
        return wake_vec;
 }
 
+#if CONFIG_SMP
 extern char *lowmem_backup;
 extern char *lowmem_backup_ptr;
 extern int lowmem_backup_size;
+#endif
 
 #define WAKEUP_BASE 0x600
 
@@ -588,12 +598,14 @@ void acpi_jump_to_wakeup(void *vector)
                return;
        }
 
+#if CONFIG_SMP
        // FIXME: This should go into the ACPI backup memory, too. No pork saussages.
        /*
         * Just restore the SMP trampoline and continue with wakeup on
         * assembly level.
         */
        memcpy(lowmem_backup_ptr, lowmem_backup, lowmem_backup_size);
+#endif
 
        /* Copy wakeup trampoline in place. */
        memcpy((void *)WAKEUP_BASE, &__wakeup, (size_t)&__wakeup_size);