Mono | 9b90824 | 2014-03-02 18:40:36 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 19 | * MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #include <string.h> |
| 23 | #include <console/console.h> |
| 24 | #include <arch/io.h> |
| 25 | #include <arch/ioapic.h> |
| 26 | #include <arch/acpi.h> |
| 27 | #include <arch/acpigen.h> |
| 28 | #include <arch/smp/mpspec.h> |
| 29 | #include <device/device.h> |
| 30 | #include <device/pci.h> |
| 31 | #include <device/pci_ids.h> |
| 32 | |
| 33 | extern const unsigned char AmlCode[]; |
| 34 | #if CONFIG_HAVE_ACPI_SLIC |
| 35 | unsigned long acpi_create_slic(unsigned long current); |
| 36 | #endif |
| 37 | |
| 38 | #include "southbridge/intel/i82801gx/nvs.h" |
| 39 | static void acpi_create_gnvs(global_nvs_t *gnvs) |
| 40 | { |
| 41 | memset((void *)gnvs, 0, sizeof(*gnvs)); |
| 42 | gnvs->apic = 1; |
| 43 | gnvs->mpen = 1; /* Enable Multi Processing */ |
| 44 | |
| 45 | /* Enable both COM ports */ |
| 46 | gnvs->cmap = 0x01; |
| 47 | gnvs->cmbp = 0x01; |
| 48 | |
| 49 | /* IGD Displays */ |
| 50 | gnvs->ndid = 3; |
| 51 | gnvs->did[0] = 0x80000100; |
| 52 | gnvs->did[1] = 0x80000240; |
| 53 | gnvs->did[2] = 0x80000410; |
| 54 | gnvs->did[3] = 0x80000410; |
| 55 | gnvs->did[4] = 0x00000005; |
| 56 | } |
| 57 | |
| 58 | unsigned long acpi_fill_madt(unsigned long current) |
| 59 | { |
| 60 | /* Local APICs */ |
| 61 | current = acpi_create_madt_lapics(current); |
| 62 | |
| 63 | /* IOAPIC */ |
| 64 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, |
| 65 | 2, IO_APIC_ADDR, 0); |
| 66 | |
| 67 | /* LAPIC_NMI */ |
| 68 | current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *) |
| 69 | current, 0, |
| 70 | MP_IRQ_POLARITY_HIGH | |
| 71 | MP_IRQ_TRIGGER_EDGE, 0x01); |
| 72 | current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *) |
| 73 | current, 1, MP_IRQ_POLARITY_HIGH | |
| 74 | MP_IRQ_TRIGGER_EDGE, 0x01); |
| 75 | |
| 76 | /* INT_SRC_OVR */ |
| 77 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 78 | current, 0, 0, 2, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_EDGE); |
| 79 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 80 | current, 0, 9, 9, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_LEVEL); |
| 81 | |
| 82 | |
| 83 | return current; |
| 84 | } |
| 85 | |
| 86 | unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) |
| 87 | { |
| 88 | generate_cpu_entries(); |
| 89 | return (unsigned long) (acpigen_get_current()); |
| 90 | } |
| 91 | |
| 92 | unsigned long acpi_fill_slit(unsigned long current) |
| 93 | { |
| 94 | // Not implemented |
| 95 | return current; |
| 96 | } |
| 97 | |
| 98 | unsigned long acpi_fill_srat(unsigned long current) |
| 99 | { |
| 100 | /* No NUMA, no SRAT */ |
| 101 | return current; |
| 102 | } |
| 103 | |
| 104 | void smm_setup_structures(void *gnvs, void *tcg, void *smi1); |
| 105 | |
| 106 | #define ALIGN_CURRENT current = (ALIGN(current, 16)) |
| 107 | unsigned long write_acpi_tables(unsigned long start) |
| 108 | { |
| 109 | unsigned long current; |
| 110 | int i; |
| 111 | acpi_rsdp_t *rsdp; |
| 112 | acpi_rsdt_t *rsdt; |
| 113 | acpi_xsdt_t *xsdt; |
| 114 | acpi_hpet_t *hpet; |
| 115 | acpi_madt_t *madt; |
| 116 | acpi_mcfg_t *mcfg; |
| 117 | acpi_fadt_t *fadt; |
| 118 | acpi_facs_t *facs; |
| 119 | #if CONFIG_HAVE_ACPI_SLIC |
| 120 | acpi_header_t *slic; |
| 121 | #endif |
| 122 | acpi_header_t *ssdt; |
| 123 | acpi_header_t *dsdt; |
| 124 | void *gnvs; |
| 125 | |
| 126 | current = start; |
| 127 | |
| 128 | /* Align ACPI tables to 16byte */ |
| 129 | ALIGN_CURRENT; |
| 130 | |
| 131 | printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start); |
| 132 | |
| 133 | /* We need at least an RSDP and an RSDT Table */ |
| 134 | rsdp = (acpi_rsdp_t *) current; |
| 135 | current += sizeof(acpi_rsdp_t); |
| 136 | ALIGN_CURRENT; |
| 137 | rsdt = (acpi_rsdt_t *) current; |
| 138 | current += sizeof(acpi_rsdt_t); |
| 139 | ALIGN_CURRENT; |
| 140 | xsdt = (acpi_xsdt_t *) current; |
| 141 | current += sizeof(acpi_xsdt_t); |
| 142 | ALIGN_CURRENT; |
| 143 | |
| 144 | /* clear all table memory */ |
| 145 | memset((void *) start, 0, current - start); |
| 146 | |
| 147 | acpi_write_rsdp(rsdp, rsdt, xsdt); |
| 148 | acpi_write_rsdt(rsdt); |
| 149 | acpi_write_xsdt(xsdt); |
| 150 | |
| 151 | /* |
| 152 | * We explicitly add these tables later on: |
| 153 | */ |
| 154 | printk(BIOS_DEBUG, "ACPI: * HPET\n"); |
| 155 | |
| 156 | hpet = (acpi_hpet_t *) current; |
| 157 | current += sizeof(acpi_hpet_t); |
| 158 | ALIGN_CURRENT; |
| 159 | acpi_create_hpet(hpet); |
| 160 | acpi_add_table(rsdp, hpet); |
| 161 | |
| 162 | /* If we want to use HPET Timers Linux wants an MADT */ |
| 163 | printk(BIOS_DEBUG, "ACPI: * MADT\n"); |
| 164 | |
| 165 | madt = (acpi_madt_t *) current; |
| 166 | acpi_create_madt(madt); |
| 167 | current += madt->header.length; |
| 168 | ALIGN_CURRENT; |
| 169 | acpi_add_table(rsdp, madt); |
| 170 | |
| 171 | printk(BIOS_DEBUG, "ACPI: * MCFG\n"); |
| 172 | mcfg = (acpi_mcfg_t *) current; |
| 173 | acpi_create_mcfg(mcfg); |
| 174 | current += mcfg->header.length; |
| 175 | ALIGN_CURRENT; |
| 176 | acpi_add_table(rsdp, mcfg); |
| 177 | |
| 178 | printk(BIOS_DEBUG, "ACPI: * FACS\n"); |
| 179 | facs = (acpi_facs_t *) current; |
| 180 | current += sizeof(acpi_facs_t); |
| 181 | ALIGN_CURRENT; |
| 182 | acpi_create_facs(facs); |
| 183 | |
| 184 | dsdt = (acpi_header_t *) current; |
| 185 | memcpy(dsdt, &AmlCode, sizeof(acpi_header_t)); |
| 186 | current += dsdt->length; |
| 187 | memcpy(dsdt, &AmlCode, dsdt->length); |
| 188 | |
| 189 | /* Fix up global NVS region for SMI handler. The GNVS region lives |
| 190 | * in the (high) table area. The low memory map looks like this: |
| 191 | * |
| 192 | * 0x00000000 - 0x000003ff Real Mode IVT |
| 193 | * 0x00000020 - 0x0000019c Low MP Table (XXX conflict?) |
| 194 | * 0x00000400 - 0x000004ff BDA (somewhat unused) |
| 195 | * 0x00000500 - 0x0000052f Moved GDT |
| 196 | * 0x00000530 - 0x00000b64 coreboot table |
| 197 | * 0x0007c000 - 0x0007dfff OS boot sector (unused?) |
| 198 | * 0x0007e000 - 0x0007ffff free to use (so no good for acpi+smi) |
| 199 | * 0x00080000 - 0x0009fbff usable ram |
| 200 | * 0x0009fc00 - 0x0009ffff EBDA (unused?) |
| 201 | * 0x000a0000 - 0x000bffff VGA memory |
| 202 | * 0x000c0000 - 0x000cffff VGA option rom |
| 203 | * 0x000d0000 - 0x000dffff free for other option roms? |
| 204 | * 0x000e0000 - 0x000fffff SeaBIOS? (conflict with low tables:) |
| 205 | * 0x000f0000 - 0x000f03ff PIRQ table |
| 206 | * 0x000f0400 - 0x000f66?? ACPI tables |
| 207 | * 0x000f66?? - 0x000f???? DMI tables |
| 208 | */ |
| 209 | |
| 210 | ALIGN_CURRENT; |
| 211 | |
| 212 | /* Pack GNVS into the ACPI table area */ |
| 213 | for (i=0; i < dsdt->length; i++) { |
| 214 | if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) { |
| 215 | printk(BIOS_DEBUG, "ACPI: Patching up global NVS in DSDT at offset 0x%04x -> 0x%08x\n", i, (u32)current); |
| 216 | *(u32*)(((u32)dsdt) + i) = current; // 0x92 bytes |
| 217 | break; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /* And fill it */ |
| 222 | acpi_create_gnvs((global_nvs_t *)current); |
| 223 | |
| 224 | /* Keep pointer around */ |
| 225 | gnvs = (void *)current; |
| 226 | |
| 227 | current += 0x100; |
| 228 | ALIGN_CURRENT; |
| 229 | |
| 230 | /* And tell SMI about it */ |
| 231 | smm_setup_structures(gnvs, NULL, NULL); |
| 232 | |
| 233 | /* We patched up the DSDT, so we need to recalculate the checksum */ |
| 234 | dsdt->checksum = 0; |
| 235 | dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length); |
| 236 | |
| 237 | printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, |
| 238 | dsdt->length); |
| 239 | |
| 240 | #if CONFIG_HAVE_ACPI_SLIC |
| 241 | printk(BIOS_DEBUG, "ACPI: * SLIC\n"); |
| 242 | slic = (acpi_header_t *)current; |
| 243 | current += acpi_create_slic(current); |
| 244 | ALIGN_CURRENT; |
| 245 | acpi_add_table(rsdp, slic); |
| 246 | #endif |
| 247 | |
| 248 | printk(BIOS_DEBUG, "ACPI: * FADT\n"); |
| 249 | fadt = (acpi_fadt_t *) current; |
| 250 | current += sizeof(acpi_fadt_t); |
| 251 | ALIGN_CURRENT; |
| 252 | |
| 253 | acpi_create_fadt(fadt, facs, dsdt); |
| 254 | acpi_add_table(rsdp, fadt); |
| 255 | |
| 256 | printk(BIOS_DEBUG, "ACPI: * SSDT\n"); |
| 257 | ssdt = (acpi_header_t *)current; |
| 258 | acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR); |
| 259 | current += ssdt->length; |
| 260 | acpi_add_table(rsdp, ssdt); |
| 261 | ALIGN_CURRENT; |
| 262 | |
| 263 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 264 | printk(BIOS_INFO, "ACPI: done.\n"); |
| 265 | |
| 266 | /* Enable Dummy DCC ON# for DVI */ |
| 267 | printk(BIOS_DEBUG, "Laptop handling...\n"); |
| 268 | outb(inb(0x60f) & ~(1 << 5), 0x60f); |
| 269 | |
| 270 | return current; |
| 271 | } |