Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <console/console.h> |
| 21 | #include <string.h> |
| 22 | #include <arch/acpi.h> |
| 23 | #include <arch/ioapic.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <device/pci_ids.h> |
| 26 | #include <cpu/x86/msr.h> |
| 27 | #include <cpu/amd/mtrr.h> |
| 28 | #include <cpu/amd/amdfam10_sysconf.h> |
| 29 | |
| 30 | #include "mb_sysconf.h" |
| 31 | |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 32 | extern const unsigned char AmlCode[]; |
| 33 | extern const unsigned char AmlCode_ssdt[]; |
| 34 | |
| 35 | #if CONFIG_ACPI_SSDTX_NUM >= 1 |
| 36 | extern const unsigned char AmlCode_ssdt2[]; |
| 37 | extern const unsigned char AmlCode_ssdt3[]; |
| 38 | extern const unsigned char AmlCode_ssdt4[]; |
| 39 | extern const unsigned char AmlCode_ssdt5[]; |
| 40 | #endif |
| 41 | |
| 42 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 43 | { |
| 44 | /* Just a dummy */ |
| 45 | return current; |
| 46 | } |
| 47 | |
| 48 | unsigned long acpi_fill_madt(unsigned long current) |
| 49 | { |
| 50 | device_t dev; |
| 51 | u32 dword; |
| 52 | u32 gsi_base=0; |
| 53 | /* create all subtables for processors */ |
| 54 | current = acpi_create_madt_lapics(current); |
| 55 | |
| 56 | /* Write SB700 IOAPIC, only one */ |
| 57 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2, |
| 58 | IO_APIC_ADDR, gsi_base); |
| 59 | /* IOAPIC on rs5690 */ |
| 60 | gsi_base += 24; /* SB700 has 24 IOAPIC entries. */ |
| 61 | dev = dev_find_slot(0, PCI_DEVFN(0, 0)); |
| 62 | if (dev) { |
| 63 | pci_write_config32(dev, 0xF8, 0x1); |
| 64 | dword = pci_read_config32(dev, 0xFC) & 0xfffffff0; |
| 65 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2+1, |
| 66 | dword, gsi_base); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 71 | current, 0, 0, 2, 0); |
| 72 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 73 | current, 0, 9, 9, 0xF); |
| 74 | /* 0: mean bus 0--->ISA */ |
| 75 | /* 0: PIC 0 */ |
| 76 | /* 2: APIC 2 */ |
Kyösti Mälkki | d874757 | 2014-06-26 05:30:54 +0300 | [diff] [blame^] | 77 | /* 5 mean: 0101 --> Edge-triggered, Active high */ |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 78 | |
| 79 | /* create all subtables for processors */ |
| 80 | /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */ |
| 81 | /* 1: LINT1 connect to NMI */ |
| 82 | |
| 83 | return current; |
| 84 | } |
| 85 | |
| 86 | unsigned long write_acpi_tables(unsigned long start) |
| 87 | { |
| 88 | unsigned long current; |
| 89 | acpi_rsdp_t *rsdp; |
| 90 | acpi_rsdt_t *rsdt; |
| 91 | acpi_hpet_t *hpet; |
| 92 | acpi_madt_t *madt; |
| 93 | acpi_srat_t *srat; |
| 94 | acpi_slit_t *slit; |
| 95 | acpi_fadt_t *fadt; |
| 96 | acpi_facs_t *facs; |
| 97 | acpi_header_t *dsdt; |
| 98 | acpi_header_t *ssdt; |
| 99 | #if CONFIG_ACPI_SSDTX_NUM >= 1 |
| 100 | acpi_header_t *ssdtx; |
| 101 | void *p; |
| 102 | int i; |
| 103 | #endif |
| 104 | |
| 105 | get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */ |
| 106 | |
| 107 | /* Align ACPI tables to 16 bytes */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 108 | start = ALIGN(start, 16); |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 109 | current = start; |
| 110 | |
| 111 | printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start); |
| 112 | |
| 113 | /* We need at least an RSDP and an RSDT Table */ |
| 114 | rsdp = (acpi_rsdp_t *) current; |
| 115 | current += sizeof(acpi_rsdp_t); |
| 116 | rsdt = (acpi_rsdt_t *) current; |
| 117 | current += sizeof(acpi_rsdt_t); |
| 118 | |
| 119 | /* clear all table memory */ |
| 120 | memset((void *)start, 0, current - start); |
| 121 | |
| 122 | acpi_write_rsdp(rsdp, rsdt, NULL); |
| 123 | acpi_write_rsdt(rsdt); |
| 124 | |
| 125 | /* |
| 126 | * We explicitly add these tables later on: |
| 127 | */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 128 | current = ALIGN(current, 8); |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 129 | printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current); |
| 130 | hpet = (acpi_hpet_t *) current; |
| 131 | current += sizeof(acpi_hpet_t); |
| 132 | acpi_create_hpet(hpet); |
| 133 | acpi_add_table(rsdp, hpet); |
| 134 | |
| 135 | /* If we want to use HPET Timers Linux wants an MADT */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 136 | current = ALIGN(current, 8); |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 137 | printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current); |
| 138 | madt = (acpi_madt_t *) current; |
| 139 | acpi_create_madt(madt); |
| 140 | current += madt->header.length; |
| 141 | acpi_add_table(rsdp, madt); |
| 142 | |
| 143 | /* SRAT */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 144 | current = ALIGN(current, 8); |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 145 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
| 146 | srat = (acpi_srat_t *) current; |
| 147 | acpi_create_srat(srat); |
| 148 | current += srat->header.length; |
| 149 | acpi_add_table(rsdp, srat); |
| 150 | |
| 151 | /* SLIT */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 152 | current = ALIGN(current, 8); |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 153 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
| 154 | slit = (acpi_slit_t *) current; |
| 155 | acpi_create_slit(slit); |
| 156 | current += slit->header.length; |
| 157 | acpi_add_table(rsdp, slit); |
| 158 | |
| 159 | /* SSDT */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 160 | current = ALIGN(current, 16); |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 161 | printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current); |
| 162 | ssdt = (acpi_header_t *)current; |
| 163 | memcpy(ssdt, &AmlCode_ssdt, sizeof(acpi_header_t)); |
| 164 | current += ssdt->length; |
| 165 | memcpy(ssdt, &AmlCode_ssdt, ssdt->length); |
| 166 | //Here you need to set value in pci1234, sblk and sbdn in get_bus_conf.c |
| 167 | update_ssdt((void*)ssdt); |
| 168 | /* recalculate checksum */ |
| 169 | ssdt->checksum = 0; |
| 170 | ssdt->checksum = acpi_checksum((unsigned char *)ssdt,ssdt->length); |
| 171 | acpi_add_table(rsdp,ssdt); |
| 172 | |
| 173 | printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current); |
| 174 | current = acpi_add_ssdt_pstates(rsdp, current); |
| 175 | |
| 176 | #if CONFIG_ACPI_SSDTX_NUM >= 1 |
| 177 | |
| 178 | /* same htio, but different position? We may have to copy, |
| 179 | change HCIN, and recalculate the checknum and add_table */ |
| 180 | |
| 181 | for(i=1;i<sysconf.hc_possible_num;i++) { // 0: is hc sblink |
| 182 | if((sysconf.pci1234[i] & 1) != 1 ) continue; |
| 183 | u8 c; |
| 184 | if (i < 7) { |
| 185 | c = (u8) ('4' + i - 1); |
| 186 | } else { |
| 187 | c = (u8) ('A' + i - 1 - 6); |
| 188 | } |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 189 | current = ALIGN(current, 8); |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 190 | printk(BIOS_DEBUG, "ACPI: * SSDT for PCI%c at %lx\n", c, current); //pci0 and pci1 are in dsdt |
| 191 | ssdtx = (acpi_header_t *)current; |
| 192 | switch (sysconf.hcid[i]) { |
| 193 | case 1: |
| 194 | p = &AmlCode_ssdt2; |
| 195 | break; |
| 196 | case 2: |
| 197 | p = &AmlCode_ssdt3; |
| 198 | break; |
| 199 | case 3: /* 8131 */ |
| 200 | p = &AmlCode_ssdt4; |
| 201 | break; |
| 202 | default: |
| 203 | /* HTX no io apic */ |
| 204 | p = &AmlCode_ssdt5; |
| 205 | break; |
| 206 | } |
| 207 | memcpy(ssdtx, p, sizeof(acpi_header_t)); |
| 208 | current += ssdtx->length; |
| 209 | memcpy(ssdtx, p, ssdtx->length); |
| 210 | update_ssdtx((void *)ssdtx, i); |
| 211 | ssdtx->checksum = 0; |
| 212 | ssdtx->checksum = acpi_checksum((u8 *)ssdtx, ssdtx->length); |
| 213 | acpi_add_table(rsdp, ssdtx); |
| 214 | } |
| 215 | #endif |
| 216 | |
| 217 | /* DSDT */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 218 | current = ALIGN(current, 8); |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 219 | printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current); |
| 220 | dsdt = (acpi_header_t *)current; // it will used by fadt |
| 221 | memcpy(dsdt, &AmlCode, sizeof(acpi_header_t)); |
| 222 | current += dsdt->length; |
| 223 | memcpy(dsdt, &AmlCode, dsdt->length); |
| 224 | printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length); |
| 225 | |
| 226 | /* FACS */ // it needs 64 bit alignment |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 227 | current = ALIGN(current, 8); |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 228 | printk(BIOS_DEBUG, "ACPI: * FACS at %lx\n", current); |
| 229 | facs = (acpi_facs_t *) current; // it will be used by fadt |
| 230 | current += sizeof(acpi_facs_t); |
| 231 | acpi_create_facs(facs); |
| 232 | |
| 233 | /* FADT */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 234 | current = ALIGN(current, 8); |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 235 | printk(BIOS_DEBUG, "ACPI: * FADT at %lx\n", current); |
| 236 | fadt = (acpi_fadt_t *) current; |
| 237 | current += sizeof(acpi_fadt_t); |
| 238 | |
| 239 | acpi_create_fadt(fadt, facs, dsdt); |
| 240 | acpi_add_table(rsdp, fadt); |
| 241 | |
Zheng Bao | 910f4ca | 2011-03-28 04:38:14 +0000 | [diff] [blame] | 242 | printk(BIOS_INFO, "ACPI: done.\n"); |
| 243 | return current; |
| 244 | } |