2cdb5c50185b626baff9e4f18fca63869fcf31cd
[coreboot.git] / src / mainboard / msi / ms9652_fam10 / acpi_tables.c
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>
9  * Copyright (C) 2007, 2008 Rudolf Marek <r.marek@assembler.cz>
10  * Copyright (C) 2009 Harald Gutmann <harald.gutmann@gmx.net>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; version 2 of the License.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
24  */
25
26 #include <console/console.h>
27 #include <string.h>
28 #include <arch/acpi.h>
29 #include <arch/smp/mpspec.h>
30 #include <device/device.h>
31 #include <device/pci_ids.h>
32 //#include "northbridge/amd/amdfam10/amdfam10_acpi.h"
33 #include <cpu/amd/model_fxx_powernow.h>
34 #include <device/pci.h>
35 #include <cpu/amd/amdfam10_sysconf.h>
36 #include "mb_sysconf.h"
37
38 extern const unsigned char AmlCode[];
39
40 unsigned long acpi_fill_mcfg(unsigned long current)
41 {
42         /* Not implemented */
43         return current;
44 }
45
46 unsigned long acpi_fill_madt(unsigned long current)
47 {
48         unsigned int gsi_base = 0x18;
49         struct mb_sysconf_t *m;
50         //extern unsigned char bus_mcp55[8];
51         //extern unsigned apicid_mcp55;
52
53         unsigned sbdn;
54         struct resource *res;
55         device_t dev;
56
57         get_bus_conf();
58         sbdn = sysconf.sbdn;
59         m = sysconf.mb;
60
61         /* Create all subtables for processors. */
62         current = acpi_create_madt_lapics(current);
63
64         /* Write SB IOAPIC. */
65         dev = dev_find_slot(m->bus_mcp55[0], PCI_DEVFN(sbdn+ 0x1,0));
66         if (dev) {
67                 res = find_resource(dev, PCI_BASE_ADDRESS_1);
68                 if (res) {
69                         current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
70                                 m->apicid_mcp55, res->base,  0);
71                 }
72         }
73
74         /* Write NB IOAPIC. */
75         dev = dev_find_slot(m->bus_mcp55[0], PCI_DEVFN(sbdn+ 0x12,1));
76         if (dev) {
77                 res = find_resource(dev, PCI_BASE_ADDRESS_1);
78                 if (res) {
79                         current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
80                                 m->apicid_mcp55++, res->base,  gsi_base);
81                 }
82         }
83
84         /* IRQ9 ACPI active low. */
85         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
86                 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
87
88         /* IRQ0 -> APIC IRQ2. */
89         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
90                 current, 0, 0, 2, 0x0);
91
92         /* Create all subtables for processors. */
93         current = acpi_create_madt_lapic_nmis(current,
94                 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
95
96         return current;
97 }
98
99 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
100 {
101         //k8acpi_write_vars();
102         //amd_model_fxx_generate_powernow(0, 0, 0);
103         //return (unsigned long) (acpigen_get_current());
104         return 0;
105 }
106
107 unsigned long write_acpi_tables(unsigned long start)
108 {
109         unsigned long current;
110         acpi_rsdp_t *rsdp;
111         acpi_srat_t *srat;
112         acpi_rsdt_t *rsdt;
113         acpi_mcfg_t *mcfg;
114         acpi_hpet_t *hpet;
115         acpi_madt_t *madt;
116         acpi_fadt_t *fadt;
117         acpi_facs_t *facs;
118         acpi_slit_t *slit;
119         acpi_header_t *ssdt;
120         acpi_header_t *dsdt;
121
122         /* Align ACPI tables to 16 byte. */
123         start = (start + 0x0f) & -0x10;
124         current = start;
125
126         printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
127
128         /* We need at least an RSDP and an RSDT table. */
129         rsdp = (acpi_rsdp_t *) current;
130         current += sizeof(acpi_rsdp_t);
131         rsdt = (acpi_rsdt_t *) current;
132         current += sizeof(acpi_rsdt_t);
133
134         /* Clear all table memory. */
135         memset((void *) start, 0, current - start);
136
137         acpi_write_rsdp(rsdp, rsdt, NULL);
138         acpi_write_rsdt(rsdt);
139
140         /* We explicitly add these tables later on: */
141         printk(BIOS_DEBUG, "ACPI:     * FACS\n");
142
143         /* we should align FACS to 64B as per ACPI specs */
144         current = ALIGN(current, 64);
145         facs = (acpi_facs_t *) current;
146         current += sizeof(acpi_facs_t);
147         acpi_create_facs(facs);
148
149         dsdt = (acpi_header_t *) current;
150         memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
151         current += dsdt->length;
152         memcpy(dsdt, &AmlCode, dsdt->length);
153         dsdt->checksum = 0;     /* Don't trust iasl to get this right. */
154         dsdt->checksum = acpi_checksum(dsdt, dsdt->length);
155         printk(BIOS_DEBUG, "ACPI:     * DSDT @ %p Length %x\n", dsdt,
156                      dsdt->length);
157         printk(BIOS_DEBUG, "ACPI:     * FADT\n");
158
159         fadt = (acpi_fadt_t *) current;
160         current += sizeof(acpi_fadt_t);
161
162         acpi_create_fadt(fadt, facs, dsdt);
163         acpi_add_table(rsdp, fadt);
164
165         printk(BIOS_DEBUG, "ACPI:    * HPET\n");
166         hpet = (acpi_hpet_t *) current;
167         current += sizeof(acpi_hpet_t);
168         acpi_create_hpet(hpet);
169         acpi_add_table(rsdp, hpet);
170
171         /* If we want to use HPET timers Linux wants an MADT. */
172         printk(BIOS_DEBUG, "ACPI:    * MADT\n");
173         madt = (acpi_madt_t *) current;
174         acpi_create_madt(madt);
175         current += madt->header.length;
176         acpi_add_table(rsdp, madt);
177
178         printk(BIOS_DEBUG, "ACPI:    * MCFG\n");
179         mcfg = (acpi_mcfg_t *) current;
180         acpi_create_mcfg(mcfg);
181         current += mcfg->header.length;
182         acpi_add_table(rsdp, mcfg);
183
184         printk(BIOS_DEBUG, "ACPI:    * SRAT\n");
185         srat = (acpi_srat_t *) current;
186         acpi_create_srat(srat);
187         current += srat->header.length;
188         acpi_add_table(rsdp, srat);
189
190         /* SLIT */
191         printk(BIOS_DEBUG, "ACPI:    * SLIT\n");
192         slit = (acpi_slit_t *) current;
193         acpi_create_slit(slit);
194         current+=slit->header.length;
195         acpi_add_table(rsdp, slit);
196
197         /* SSDT */
198         printk(BIOS_DEBUG, "ACPI:    * SSDT\n");
199         ssdt = (acpi_header_t *)current;
200
201         acpi_create_ssdt_generator(ssdt, "DYNADATA");
202         current += ssdt->length;
203         acpi_add_table(rsdp, ssdt);
204
205         printk(BIOS_INFO, "ACPI: done.\n");
206         return current;
207 }