move amd K8/Fam10 "bus detection" function prototypes to a common place.
[coreboot.git] / src / mainboard / amd / dbm690t / acpi_tables.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 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>
23 #include <device/pci.h>
24 #include <device/pci_ids.h>
25 #include <cpu/x86/msr.h>
26 #include <cpu/amd/mtrr.h>
27 #include <cpu/amd/amdk8_sysconf.h>
28 #include <../../../northbridge/amd/amdk8/amdk8_acpi.h>
29 #include <arch/cpu.h>
30 #include <cpu/amd/model_fxx_powernow.h>
31
32 extern u16 pm_base;
33
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
45 static 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
60 extern const acpi_header_t AmlCode;
61
62 #define IO_APIC_ADDR    0xfec00000UL
63
64 unsigned long acpi_fill_mcfg(unsigned long current)
65 {
66         /* Just a dummy */
67         return current;
68 }
69
70 unsigned long acpi_fill_madt(unsigned long current)
71 {
72         /* create all subtables for processors */
73         current = acpi_create_madt_lapics(current);
74
75         /* Write SB600 IOAPIC, only one */
76         current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2,
77                                            IO_APIC_ADDR, 0);
78
79         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
80                                                 current, 0, 0, 2, 0);
81         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
82                                                 current, 0, 9, 9, 0xF);
83         /* 0: mean bus 0--->ISA */
84         /* 0: PIC 0 */
85         /* 2: APIC 2 */
86         /* 5 mean: 0101 --> Edige-triggered, Active high */
87
88         /* create all subtables for processors */
89         /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
90         /* 1: LINT1 connect to NMI */
91
92         return current;
93 }
94
95
96
97 static void update_ssdtx(void *ssdtx, int i)
98 {
99         uint8_t *PCI;
100         uint8_t *HCIN;
101         uint8_t *UID;
102
103         PCI = ssdtx + 0x32;
104         HCIN = ssdtx + 0x39;
105         UID = ssdtx + 0x40;
106
107         if (i < 7) {
108                 *PCI = (uint8_t) ('4' + i - 1);
109         } else {
110                 *PCI = (uint8_t) ('A' + i - 1 - 6);
111         }
112         *HCIN = (uint8_t) i;
113         *UID = (uint8_t) (i + 3);
114
115         /* FIXME: need to update the GSI id in the ssdtx too */
116
117 }
118
119 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) {
120         k8acpi_write_vars();
121         amd_model_fxx_generate_powernow(pm_base + 8, 6, 1);
122         return (unsigned long) (acpigen_get_current());
123 }
124
125 unsigned long write_acpi_tables(unsigned long start)
126 {
127         unsigned long current;
128         acpi_rsdp_t *rsdp;
129         acpi_rsdt_t *rsdt;
130         acpi_hpet_t *hpet;
131         acpi_madt_t *madt;
132         acpi_fadt_t *fadt;
133         acpi_facs_t *facs;
134         acpi_header_t *dsdt;
135         acpi_header_t *ssdt;
136
137         get_bus_conf();         /* it will get sblk, pci1234, hcdn, and sbdn */
138
139         /* Align ACPI tables to 16byte */
140         start = (start + 0x0f) & -0x10;
141         current = start;
142
143         printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
144
145         /* We need at least an RSDP and an RSDT Table */
146         rsdp = (acpi_rsdp_t *) current;
147         current += sizeof(acpi_rsdp_t);
148         rsdt = (acpi_rsdt_t *) current;
149         current += sizeof(acpi_rsdt_t);
150
151         /* clear all table memory */
152         memset((void *)start, 0, current - start);
153
154         acpi_write_rsdp(rsdp, rsdt, NULL);
155         acpi_write_rsdt(rsdt);
156
157         /*
158          * We explicitly add these tables later on:
159          */
160         /* If we want to use HPET Timers Linux wants an MADT */
161         printk(BIOS_DEBUG, "ACPI:    * HPET\n");
162         hpet = (acpi_hpet_t *) current;
163         current += sizeof(acpi_hpet_t);
164         acpi_create_hpet(hpet);
165         acpi_add_table(rsdp, hpet);
166
167         printk(BIOS_DEBUG, "ACPI:    * MADT\n");
168         madt = (acpi_madt_t *) current;
169         acpi_create_madt(madt);
170         current += madt->header.length;
171         acpi_add_table(rsdp, madt);
172
173         /* SSDT */
174         printk(BIOS_DEBUG, "ACPI:    * SSDT\n");
175         ssdt = (acpi_header_t *)current;
176
177         acpi_create_ssdt_generator(ssdt, "DYNADATA");
178         current += ssdt->length;
179         acpi_add_table(rsdp, ssdt);
180
181         /* FACS */
182         printk(BIOS_DEBUG, "ACPI:    * FACS\n");
183         facs = (acpi_facs_t *) current;
184         current += sizeof(acpi_facs_t);
185         acpi_create_facs(facs);
186
187         /* DSDT */
188         printk(BIOS_DEBUG, "ACPI:    * DSDT\n");
189         dsdt = (acpi_header_t *)current;
190         current += AmlCode.length;
191         memcpy((void *)dsdt, &AmlCode, AmlCode.length);
192         printk(BIOS_DEBUG, "ACPI:    * DSDT @ %p Length %x\n", dsdt, dsdt->length);
193         /* FADT */
194         printk(BIOS_DEBUG, "ACPI:    * FADT\n");
195         fadt = (acpi_fadt_t *) current;
196         current += sizeof(acpi_fadt_t);
197
198         acpi_create_fadt(fadt, facs, dsdt);
199         acpi_add_table(rsdp, fadt);
200
201 #if DUMP_ACPI_TABLES == 1
202         printk(BIOS_DEBUG, "rsdp\n");
203         dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
204
205         printk(BIOS_DEBUG, "rsdt\n");
206         dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
207
208         printk(BIOS_DEBUG, "madt\n");
209         dump_mem(madt, ((void *)madt) + madt->header.length);
210
211         printk(BIOS_DEBUG, "ssdt\n");
212         dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
213
214         printk(BIOS_DEBUG, "fadt\n");
215         dump_mem(fadt, ((void *)fadt) + fadt->header.length);
216 #endif
217
218         printk(BIOS_INFO, "ACPI: done.\n");
219         return current;
220 }