blob: da6571d58ef538b05e669e3626ebbfd2dbe27c34 [file] [log] [blame]
Rudolf Marek133647a2010-04-05 19:47:34 +00001/*
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
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <console/console.h>
21#include <string.h>
22#include <arch/acpi.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000023#include <arch/ioapic.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000024#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/amdk8_sysconf.h>
stepan8301d832010-12-08 07:07:33 +000029#include "northbridge/amd/amdk8/acpi.h"
Rudolf Marek133647a2010-04-05 19:47:34 +000030#include <arch/cpu.h>
31#include <cpu/amd/model_fxx_powernow.h>
Rudolf Marek33109342010-12-11 22:26:10 +000032#include <southbridge/amd/sb700/sb700.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000033
34#define DUMP_ACPI_TABLES 0
35
36/*
37* Assume the max pstate number is 8
38* 0x21(33 bytes) is one package length of _PSS package
39*/
40
41#define Maxpstate 8
42#define Defpkglength 0x21
43
44#if DUMP_ACPI_TABLES == 1
45static void dump_mem(u32 start, u32 end)
46{
47
48 u32 i;
49 print_debug("dump_mem:");
50 for (i = start; i < end; i++) {
51 if ((i & 0xf) == 0) {
52 printk(BIOS_DEBUG, "\n%08x:", i);
53 }
54 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
55 }
56 print_debug("\n");
57}
58#endif
59
Myles Watsonae608552010-04-09 03:41:23 +000060extern const unsigned char AmlCode[];
Rudolf Marek133647a2010-04-05 19:47:34 +000061
62#if CONFIG_ACPI_SSDTX_NUM >= 1
Myles Watsonae608552010-04-09 03:41:23 +000063extern const unsigned char AmlCode_ssdt2[];
64extern const unsigned char AmlCode_ssdt3[];
65extern const unsigned char AmlCode_ssdt4[];
66extern const unsigned char AmlCode_ssdt5[];
Rudolf Marek133647a2010-04-05 19:47:34 +000067#endif
68
Rudolf Marek133647a2010-04-05 19:47:34 +000069unsigned long acpi_fill_mcfg(unsigned long current)
70{
71 /* Just a dummy */
72 return current;
73}
74
75unsigned long acpi_fill_madt(unsigned long current)
76{
77 /* create all subtables for processors */
78 current = acpi_create_madt_lapics(current);
79
80 /* Write SB700 IOAPIC, only one */
81 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2,
82 IO_APIC_ADDR, 0);
83
84 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
85 current, 0, 0, 2, 0);
86 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
87 current, 0, 9, 9, 0xF);
88 /* 0: mean bus 0--->ISA */
89 /* 0: PIC 0 */
90 /* 2: APIC 2 */
91 /* 5 mean: 0101 --> Edige-triggered, Active high */
92
93 /* create all subtables for processors */
94 /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
95 /* 1: LINT1 connect to NMI */
96
97 return current;
98}
99
Rudolf Marek133647a2010-04-05 19:47:34 +0000100unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) {
101 k8acpi_write_vars();
Rudolf Marek33109342010-12-11 22:26:10 +0000102 amd_model_fxx_generate_powernow(ACPI_CPU_CONTROL, 6, 1);
Rudolf Marek133647a2010-04-05 19:47:34 +0000103 return (unsigned long) (acpigen_get_current());
104}
105
106unsigned long write_acpi_tables(unsigned long start)
107{
108 unsigned long current;
109 acpi_rsdp_t *rsdp;
110 acpi_rsdt_t *rsdt;
111 acpi_hpet_t *hpet;
112 acpi_madt_t *madt;
113 acpi_fadt_t *fadt;
114 acpi_facs_t *facs;
115 acpi_header_t *dsdt;
116 acpi_header_t *ssdt;
117#if CONFIG_ACPI_SSDTX_NUM >= 1
118 acpi_header_t *ssdtx;
Myles Watsonae608552010-04-09 03:41:23 +0000119 void *p;
Rudolf Marek133647a2010-04-05 19:47:34 +0000120 int i;
121#endif
122
123 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
124
125 /* Align ACPI tables to 16 bytes */
126 start = (start + 0x0f) & -0x10;
127 current = start;
128
129 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
130
131 /* We need at least an RSDP and an RSDT Table */
132 rsdp = (acpi_rsdp_t *) current;
133 current += sizeof(acpi_rsdp_t);
134 rsdt = (acpi_rsdt_t *) current;
135 current += sizeof(acpi_rsdt_t);
136
137 /* clear all table memory */
138 memset((void *)start, 0, current - start);
139
140 acpi_write_rsdp(rsdp, rsdt, NULL);
141 acpi_write_rsdt(rsdt);
142
143 /*
144 * We explicitly add these tables later on:
145 */
146 /* If we want to use HPET Timers Linux wants an MADT */
147 printk(BIOS_DEBUG, "ACPI: * HPET\n");
148 hpet = (acpi_hpet_t *) current;
149 current += sizeof(acpi_hpet_t);
150 acpi_create_hpet(hpet);
151 acpi_add_table(rsdp, hpet);
152
153 printk(BIOS_DEBUG, "ACPI: * MADT\n");
154 madt = (acpi_madt_t *) current;
155 acpi_create_madt(madt);
156 current += madt->header.length;
157 acpi_add_table(rsdp, madt);
158
159 /* SSDT */
160 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
161 ssdt = (acpi_header_t *)current;
162
163 acpi_create_ssdt_generator(ssdt, "DYNADATA");
164 current += ssdt->length;
165 acpi_add_table(rsdp, ssdt);
166
167#if CONFIG_ACPI_SSDTX_NUM >= 1
168
169 /* same htio, but different position? We may have to copy, change HCIN, and recalculate the checknum and add_table */
170
171 for (i = 1; i < sysconf.hc_possible_num; i++) { /* 0: is hc sblink */
172 if ((sysconf.pci1234[i] & 1) != 1)
173 continue;
174 u8 c;
175 if (i < 7) {
176 c = (u8) ('4' + i - 1);
177 } else {
178 c = (u8) ('A' + i - 1 - 6);
179 }
180 printk(BIOS_DEBUG, "ACPI: * SSDT for PCI%c Aka hcid = %d\n", c, sysconf.hcid[i]); /* pci0 and pci1 are in dsdt */
181 current = (current + 0x07) & -0x08;
182 ssdtx = (acpi_header_t *) current;
183 switch (sysconf.hcid[i]) {
184 case 1: /* 8132 */
185 p = &AmlCode_ssdt2;
186 break;
187 case 2: /* 8151 */
188 p = &AmlCode_ssdt3;
189 break;
190 case 3: /* 8131 */
191 p = &AmlCode_ssdt4;
192 break;
193 default:
194 /* HTX no io apic */
195 p = &AmlCode_ssdt5;
196 break;
197 }
Myles Watsonae608552010-04-09 03:41:23 +0000198 memcpy(ssdtx, p, sizeof(acpi_header_t));
199 current += ssdtx->length;
200 memcpy(ssdtx, p, ssdtx->length);
Rudolf Marek133647a2010-04-05 19:47:34 +0000201 update_ssdtx((void *)ssdtx, i);
202 ssdtx->checksum = 0;
203 ssdtx->checksum = acpi_checksum((u8 *)ssdtx, ssdtx->length);
204 acpi_add_table(rsdp, ssdtx);
205 }
206#endif
207
208 /* FACS */
209 printk(BIOS_DEBUG, "ACPI: * FACS\n");
210 facs = (acpi_facs_t *) current;
211 current += sizeof(acpi_facs_t);
212 acpi_create_facs(facs);
213
214 /* DSDT */
215 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
Myles Watsonae608552010-04-09 03:41:23 +0000216 dsdt = (acpi_header_t *)current;
217 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
Rudolf Marek133647a2010-04-05 19:47:34 +0000218 current += dsdt->length;
Myles Watsonae608552010-04-09 03:41:23 +0000219 memcpy(dsdt, &AmlCode, dsdt->length);
Rudolf Marek133647a2010-04-05 19:47:34 +0000220 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, dsdt->length);
221 /* FADT */
222 printk(BIOS_DEBUG, "ACPI: * FADT\n");
223 fadt = (acpi_fadt_t *) current;
224 current += sizeof(acpi_fadt_t);
225
226 acpi_create_fadt(fadt, facs, dsdt);
227 acpi_add_table(rsdp, fadt);
228
229#if DUMP_ACPI_TABLES == 1
230 printk(BIOS_DEBUG, "rsdp\n");
231 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
232
233 printk(BIOS_DEBUG, "rsdt\n");
234 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
235
236 printk(BIOS_DEBUG, "madt\n");
237 dump_mem(madt, ((void *)madt) + madt->header.length);
238
239 printk(BIOS_DEBUG, "ssdt\n");
240 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
241
242 printk(BIOS_DEBUG, "fadt\n");
243 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
244#endif
245
246 printk(BIOS_INFO, "ACPI: done.\n");
247 return current;
248}