Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Written by Stefan Reinauer <stepan@openbios.org>. |
| 5 | * ACPI FADT, FACS, and DSDT table support added by |
| 6 | * |
| 7 | * Copyright (C) 2004 Stefan Reinauer <stepan@openbios.org> |
| 8 | * Copyright (C) 2005 Nick Barker <nick.barker9@btinternet.com> |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame^] | 9 | * Copyright (C) 2007, 2008 Rudolf Marek <r.marek@assembler.cz> |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License v2 as published by |
| 13 | * the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | */ |
| 24 | |
| 25 | #include <console/console.h> |
| 26 | #include <string.h> |
| 27 | #include <arch/acpi.h> |
| 28 | #include <arch/smp/mpspec.h> |
| 29 | #include <device/device.h> |
| 30 | #include <device/pci_ids.h> |
| 31 | #include <../../../southbridge/via/vt8237r/vt8237r.h> |
| 32 | #include <../../../southbridge/via/k8t890/k8t890.h> |
| 33 | |
| 34 | extern unsigned char AmlCode[]; |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame^] | 35 | extern unsigned char AmlCode_ssdt[]; |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 36 | |
| 37 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 38 | { |
| 39 | device_t dev; |
| 40 | struct resource *res; |
| 41 | |
| 42 | dev = dev_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8T890CE_5, 0); |
| 43 | if (!dev) |
| 44 | return current; |
| 45 | |
| 46 | res = find_resource(dev, K8T890_MMCONFIG_MBAR); |
| 47 | if (res) { |
| 48 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) |
| 49 | current, res->base, 0x0, 0x0, 0xff); |
| 50 | } |
| 51 | return current; |
| 52 | } |
| 53 | |
| 54 | unsigned long acpi_fill_madt(unsigned long current) |
| 55 | { |
| 56 | unsigned int gsi_base = 0x18; |
| 57 | |
| 58 | /* Create all subtables for processors. */ |
| 59 | current = acpi_create_madt_lapics(current); |
| 60 | |
| 61 | /* Write SB IOAPIC. */ |
| 62 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, |
| 63 | VT8237R_APIC_ID, VT8237R_APIC_BASE, 0); |
| 64 | |
| 65 | /* Write NB IOAPIC. */ |
| 66 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, |
| 67 | K8T890_APIC_ID, K8T890_APIC_BASE, gsi_base); |
| 68 | |
| 69 | /* IRQ9 ACPI active low. */ |
| 70 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 71 | current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW); |
| 72 | |
| 73 | /* IRQ0 -> APIC IRQ2. */ |
| 74 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 75 | current, 0, 0, 2, 0x0); |
| 76 | |
| 77 | /* Create all subtables for processors. */ |
| 78 | current = acpi_create_madt_lapic_nmis(current, |
| 79 | MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1); |
| 80 | |
| 81 | return current; |
| 82 | } |
| 83 | |
| 84 | unsigned long write_acpi_tables(unsigned long start) |
| 85 | { |
| 86 | unsigned long current; |
| 87 | acpi_rsdp_t *rsdp; |
| 88 | acpi_srat_t *srat; |
| 89 | acpi_rsdt_t *rsdt; |
| 90 | acpi_mcfg_t *mcfg; |
| 91 | acpi_hpet_t *hpet; |
| 92 | acpi_madt_t *madt; |
| 93 | acpi_fadt_t *fadt; |
| 94 | acpi_facs_t *facs; |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame^] | 95 | acpi_slit_t *slit; |
| 96 | acpi_header_t *ssdt; |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 97 | acpi_header_t *dsdt; |
| 98 | |
| 99 | /* Align ACPI tables to 16 byte. */ |
| 100 | start = (start + 0x0f) & -0x10; |
| 101 | current = start; |
| 102 | |
| 103 | printk_info("ACPI: Writing ACPI tables at %lx...\n", start); |
| 104 | |
| 105 | /* We need at least an RSDP and an RSDT table. */ |
| 106 | rsdp = (acpi_rsdp_t *) current; |
| 107 | current += sizeof(acpi_rsdp_t); |
| 108 | rsdt = (acpi_rsdt_t *) current; |
| 109 | current += sizeof(acpi_rsdt_t); |
| 110 | |
| 111 | /* Clear all table memory. */ |
| 112 | memset((void *) start, 0, current - start); |
| 113 | |
| 114 | acpi_write_rsdp(rsdp, rsdt); |
| 115 | acpi_write_rsdt(rsdt); |
| 116 | |
| 117 | /* We explicitly add these tables later on: */ |
| 118 | printk_debug("ACPI: * FACS\n"); |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame^] | 119 | |
| 120 | /* we should align FACS to 64B as per ACPI specs */ |
| 121 | |
| 122 | current = ALIGN(current, 64); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 123 | facs = (acpi_facs_t *) current; |
| 124 | current += sizeof(acpi_facs_t); |
| 125 | acpi_create_facs(facs); |
| 126 | |
| 127 | dsdt = (acpi_header_t *) current; |
| 128 | current += ((acpi_header_t *) AmlCode)->length; |
| 129 | memcpy((void *) dsdt, (void *) AmlCode, |
| 130 | ((acpi_header_t *) AmlCode)->length); |
| 131 | dsdt->checksum = 0; /* Don't trust iasl to get this right. */ |
| 132 | dsdt->checksum = acpi_checksum(dsdt, dsdt->length); |
| 133 | printk_debug("ACPI: * DSDT @ %08x Length %x\n", dsdt, |
| 134 | dsdt->length); |
| 135 | printk_debug("ACPI: * FADT\n"); |
| 136 | |
| 137 | fadt = (acpi_fadt_t *) current; |
| 138 | current += sizeof(acpi_fadt_t); |
| 139 | |
| 140 | acpi_create_fadt(fadt, facs, dsdt); |
| 141 | acpi_add_table(rsdt, fadt); |
| 142 | |
| 143 | printk_debug("ACPI: * HPET\n"); |
| 144 | hpet = (acpi_hpet_t *) current; |
| 145 | current += sizeof(acpi_hpet_t); |
| 146 | acpi_create_hpet(hpet); |
| 147 | acpi_add_table(rsdt, hpet); |
| 148 | |
| 149 | /* If we want to use HPET timers Linux wants an MADT. */ |
| 150 | printk_debug("ACPI: * MADT\n"); |
| 151 | madt = (acpi_madt_t *) current; |
| 152 | acpi_create_madt(madt); |
| 153 | current += madt->header.length; |
| 154 | acpi_add_table(rsdt, madt); |
| 155 | |
| 156 | printk_debug("ACPI: * MCFG\n"); |
| 157 | mcfg = (acpi_mcfg_t *) current; |
| 158 | acpi_create_mcfg(mcfg); |
| 159 | current += mcfg->header.length; |
| 160 | acpi_add_table(rsdt, mcfg); |
| 161 | |
| 162 | printk_debug("ACPI: * SRAT\n"); |
| 163 | srat = (acpi_srat_t *) current; |
| 164 | acpi_create_srat(srat); |
| 165 | current += srat->header.length; |
| 166 | acpi_add_table(rsdt, srat); |
| 167 | |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame^] | 168 | /* SLIT */ |
| 169 | printk_debug("ACPI: * SLIT\n"); |
| 170 | slit = (acpi_slit_t *) current; |
| 171 | acpi_create_slit(slit); |
| 172 | current+=slit->header.length; |
| 173 | acpi_add_table(rsdt,slit); |
| 174 | |
| 175 | /* SSDT */ |
| 176 | printk_debug("ACPI: * SSDT\n"); |
| 177 | ssdt = (acpi_header_t *)current; |
| 178 | current += ((acpi_header_t *)AmlCode_ssdt)->length; |
| 179 | memcpy((void *)ssdt, (void *)AmlCode_ssdt, ((acpi_header_t *)AmlCode_ssdt)->length); |
| 180 | update_ssdt((void*)ssdt); |
| 181 | /* recalculate checksum */ |
| 182 | ssdt->checksum = 0; |
| 183 | ssdt->checksum = acpi_checksum((unsigned char *)ssdt,ssdt->length); |
| 184 | acpi_add_table(rsdt,ssdt); |
| 185 | |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 186 | printk_info("ACPI: done.\n"); |
| 187 | return current; |
| 188 | } |