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>. |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 5 | * ACPI FADT, FACS, and DSDT table support added by |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 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 |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; version 2 of the License. |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 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> |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame^] | 28 | #include <arch/acpigen.h> |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 29 | #include <arch/smp/mpspec.h> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 30 | #include <arch/ioapic.h> |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 31 | #include <device/device.h> |
| 32 | #include <device/pci_ids.h> |
Uwe Hermann | 5df4168 | 2010-09-25 16:17:20 +0000 | [diff] [blame] | 33 | #include "southbridge/via/vt8237r/vt8237r.h" |
| 34 | #include "southbridge/via/k8t890/k8t890.h" |
| 35 | #include "northbridge/amd/amdk8/amdk8_acpi.h" |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 36 | #include <cpu/amd/model_fxx_powernow.h> |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 37 | |
Myles Watson | ae60855 | 2010-04-09 03:41:23 +0000 | [diff] [blame] | 38 | extern const unsigned char AmlCode[]; |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 39 | |
| 40 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 41 | { |
| 42 | device_t dev; |
| 43 | struct resource *res; |
| 44 | |
Rudolf Marek | b2bd996 | 2009-07-23 08:10:51 +0000 | [diff] [blame] | 45 | dev = dev_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8M890CE_5, 0); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 46 | if (!dev) |
| 47 | return current; |
| 48 | |
| 49 | res = find_resource(dev, K8T890_MMCONFIG_MBAR); |
| 50 | if (res) { |
| 51 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) |
| 52 | current, res->base, 0x0, 0x0, 0xff); |
| 53 | } |
| 54 | return current; |
| 55 | } |
| 56 | |
| 57 | unsigned long acpi_fill_madt(unsigned long current) |
| 58 | { |
| 59 | unsigned int gsi_base = 0x18; |
| 60 | |
| 61 | /* Create all subtables for processors. */ |
| 62 | current = acpi_create_madt_lapics(current); |
| 63 | |
| 64 | /* Write SB IOAPIC. */ |
| 65 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 66 | VT8237R_APIC_ID, IO_APIC_ADDR, 0); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 67 | |
| 68 | /* Write NB IOAPIC. */ |
| 69 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, |
| 70 | K8T890_APIC_ID, K8T890_APIC_BASE, gsi_base); |
| 71 | |
| 72 | /* IRQ9 ACPI active low. */ |
| 73 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 74 | current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW); |
| 75 | |
| 76 | /* IRQ0 -> APIC IRQ2. */ |
| 77 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 78 | current, 0, 0, 2, 0x0); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 79 | |
| 80 | /* Create all subtables for processors. */ |
| 81 | current = acpi_create_madt_lapic_nmis(current, |
| 82 | MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1); |
| 83 | |
| 84 | return current; |
| 85 | } |
| 86 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 87 | unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) |
Stefan Reinauer | decdb3c | 2009-03-31 14:10:42 +0000 | [diff] [blame] | 88 | { |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 89 | k8acpi_write_vars(); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 90 | amd_model_fxx_generate_powernow(0, 0, 0); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame^] | 91 | acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS"); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 92 | return (unsigned long) (acpigen_get_current()); |
| 93 | } |
| 94 | |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 95 | unsigned long write_acpi_tables(unsigned long start) |
| 96 | { |
| 97 | unsigned long current; |
| 98 | acpi_rsdp_t *rsdp; |
| 99 | acpi_srat_t *srat; |
| 100 | acpi_rsdt_t *rsdt; |
| 101 | acpi_mcfg_t *mcfg; |
| 102 | acpi_hpet_t *hpet; |
| 103 | acpi_madt_t *madt; |
| 104 | acpi_fadt_t *fadt; |
| 105 | acpi_facs_t *facs; |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame] | 106 | acpi_slit_t *slit; |
| 107 | acpi_header_t *ssdt; |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 108 | acpi_header_t *dsdt; |
| 109 | |
| 110 | /* Align ACPI tables to 16 byte. */ |
| 111 | start = (start + 0x0f) & -0x10; |
| 112 | current = start; |
| 113 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 114 | printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 115 | |
| 116 | /* We need at least an RSDP and an RSDT table. */ |
| 117 | rsdp = (acpi_rsdp_t *) current; |
| 118 | current += sizeof(acpi_rsdp_t); |
| 119 | rsdt = (acpi_rsdt_t *) current; |
| 120 | current += sizeof(acpi_rsdt_t); |
| 121 | |
| 122 | /* Clear all table memory. */ |
| 123 | memset((void *) start, 0, current - start); |
| 124 | |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 125 | acpi_write_rsdp(rsdp, rsdt, NULL); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 126 | acpi_write_rsdt(rsdt); |
| 127 | |
| 128 | /* We explicitly add these tables later on: */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 129 | printk(BIOS_DEBUG, "ACPI: * FACS\n"); |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame] | 130 | |
| 131 | /* we should align FACS to 64B as per ACPI specs */ |
| 132 | |
| 133 | current = ALIGN(current, 64); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 134 | facs = (acpi_facs_t *) current; |
| 135 | current += sizeof(acpi_facs_t); |
| 136 | acpi_create_facs(facs); |
| 137 | |
| 138 | dsdt = (acpi_header_t *) current; |
Myles Watson | ae60855 | 2010-04-09 03:41:23 +0000 | [diff] [blame] | 139 | memcpy(dsdt, &AmlCode, sizeof(acpi_header_t)); |
| 140 | current += dsdt->length; |
| 141 | memcpy(dsdt, &AmlCode, dsdt->length); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 142 | dsdt->checksum = 0; /* Don't trust iasl to get this right. */ |
Myles Watson | ae60855 | 2010-04-09 03:41:23 +0000 | [diff] [blame] | 143 | dsdt->checksum = acpi_checksum((u8*)dsdt, dsdt->length); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 144 | printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 145 | dsdt->length); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 146 | printk(BIOS_DEBUG, "ACPI: * FADT\n"); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 147 | |
| 148 | fadt = (acpi_fadt_t *) current; |
| 149 | current += sizeof(acpi_fadt_t); |
| 150 | |
| 151 | acpi_create_fadt(fadt, facs, dsdt); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 152 | acpi_add_table(rsdp, fadt); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 153 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 154 | printk(BIOS_DEBUG, "ACPI: * HPET\n"); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 155 | hpet = (acpi_hpet_t *) current; |
| 156 | current += sizeof(acpi_hpet_t); |
| 157 | acpi_create_hpet(hpet); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 158 | acpi_add_table(rsdp, hpet); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 159 | |
| 160 | /* If we want to use HPET timers Linux wants an MADT. */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 161 | printk(BIOS_DEBUG, "ACPI: * MADT\n"); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 162 | madt = (acpi_madt_t *) current; |
| 163 | acpi_create_madt(madt); |
| 164 | current += madt->header.length; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 165 | acpi_add_table(rsdp, madt); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 166 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 167 | printk(BIOS_DEBUG, "ACPI: * MCFG\n"); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 168 | mcfg = (acpi_mcfg_t *) current; |
| 169 | acpi_create_mcfg(mcfg); |
| 170 | current += mcfg->header.length; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 171 | acpi_add_table(rsdp, mcfg); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 172 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 173 | printk(BIOS_DEBUG, "ACPI: * SRAT\n"); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 174 | srat = (acpi_srat_t *) current; |
| 175 | acpi_create_srat(srat); |
| 176 | current += srat->header.length; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 177 | acpi_add_table(rsdp, srat); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 178 | |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame] | 179 | /* SLIT */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 180 | printk(BIOS_DEBUG, "ACPI: * SLIT\n"); |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame] | 181 | slit = (acpi_slit_t *) current; |
| 182 | acpi_create_slit(slit); |
| 183 | current+=slit->header.length; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 184 | acpi_add_table(rsdp,slit); |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame] | 185 | |
| 186 | /* SSDT */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 187 | printk(BIOS_DEBUG, "ACPI: * SSDT\n"); |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame] | 188 | ssdt = (acpi_header_t *)current; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 189 | |
| 190 | acpi_create_ssdt_generator(ssdt, "DYNADATA"); |
| 191 | current += ssdt->length; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 192 | acpi_add_table(rsdp, ssdt); |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame] | 193 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 194 | printk(BIOS_INFO, "ACPI: done.\n"); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 195 | return current; |
| 196 | } |