blob: 400dc0ee8082d957cb587cf81f2f22622b30ae87 [file] [log] [blame]
Yinghai Luc34e3ab2006-10-12 00:58:20 +00001/*
2 * Island Aruma ACPI support
3 * written by Stefan Reinauer <stepan@openbios.org>
4 * (C) 2005 Stefan Reinauer
5 *
6 *
7 * Copyright 2005 AMD
8 * 2005.9 yhlu modify that to more dynamic for AMD Opteron Based MB
9 */
10
11#include <console/console.h>
12#include <string.h>
13#include <arch/acpi.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000014#include <arch/ioapic.h>
Yinghai Luc34e3ab2006-10-12 00:58:20 +000015#include <device/pci.h>
16#include <device/pci_ids.h>
17#include <cpu/x86/msr.h>
18#include <cpu/amd/mtrr.h>
19#include <cpu/amd/amdk8_sysconf.h>
stepan8301d832010-12-08 07:07:33 +000020#include "northbridge/amd/amdk8/acpi.h"
Yinghai Luc34e3ab2006-10-12 00:58:20 +000021#include "mb_sysconf.h"
22
23#define DUMP_ACPI_TABLES 0
24
25#if DUMP_ACPI_TABLES == 1
26static void dump_mem(unsigned start, unsigned end)
27{
Stefan Reinauer14e22772010-04-27 06:56:47 +000028
Yinghai Luc34e3ab2006-10-12 00:58:20 +000029 unsigned i;
30 print_debug("dump_mem:");
31 for(i=start;i<end;i++) {
32 if((i & 0xf)==0) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000033 printk(BIOS_DEBUG, "\n%08x:", i);
Yinghai Luc34e3ab2006-10-12 00:58:20 +000034 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000035 printk(BIOS_DEBUG, " %02x", (unsigned char)*((unsigned char *)i));
Yinghai Luc34e3ab2006-10-12 00:58:20 +000036 }
37 print_debug("\n");
38 }
39#endif
40
Myles Watsonae608552010-04-09 03:41:23 +000041extern const unsigned char AmlCode[];
Yinghai Luc34e3ab2006-10-12 00:58:20 +000042
Stefan Reinauer08670622009-06-30 15:17:49 +000043#if CONFIG_ACPI_SSDTX_NUM >= 1
Myles Watsonae608552010-04-09 03:41:23 +000044extern const unsigned char AmlCode_ssdt2[];
45extern const unsigned char AmlCode_ssdt3[];
46extern const unsigned char AmlCode_ssdt4[];
47extern const unsigned char AmlCode_ssdt5[];
Yinghai Luc34e3ab2006-10-12 00:58:20 +000048#endif
49
Stefan Reinauer2cb70142007-11-04 16:50:27 +000050unsigned long acpi_fill_mcfg(unsigned long current)
51{
52 /* Just a dummy */
53 return current;
54}
55
56
Yinghai Luc34e3ab2006-10-12 00:58:20 +000057unsigned long acpi_fill_madt(unsigned long current)
58{
59 unsigned int gsi_base=0x18;
60
61 struct mb_sysconf_t *m;
62
63 m = sysconf.mb;
Stefan Reinauer14e22772010-04-27 06:56:47 +000064
Yinghai Luc34e3ab2006-10-12 00:58:20 +000065 /* create all subtables for processors */
66 current = acpi_create_madt_lapics(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +000067
Yinghai Luc34e3ab2006-10-12 00:58:20 +000068 /* Write 8111 IOAPIC */
69 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8111,
70 IO_APIC_ADDR, 0);
71
72 /* Write all 8131 IOAPICs */
73 {
74 device_t dev;
75 struct resource *res;
76 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0]&0xff), 1));
77 if (dev) {
78 res = find_resource(dev, PCI_BASE_ADDRESS_0);
79 if (res) {
80 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_1,
81 res->base, gsi_base );
82 gsi_base+=4;
83
84 }
85 }
86 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0] & 0xff)+1, 1));
87 if (dev) {
88 res = find_resource(dev, PCI_BASE_ADDRESS_0);
89 if (res) {
90 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_2,
91 res->base, gsi_base );
92 gsi_base+=4;
93 }
94 }
95
96 int i;
97 int j = 0;
98
99 for(i=1; i< sysconf.hc_possible_num; i++) {
Stefan Reinauer50776fa2010-03-17 04:40:15 +0000100 unsigned d = 0;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000101 if(!(sysconf.pci1234[i] & 0x1) ) continue;
102 // 8131 need to use +4
Stefan Reinauer14e22772010-04-27 06:56:47 +0000103
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000104 switch (sysconf.hcid[i]) {
105 case 1:
106 d = 7;
107 break;
108 case 3:
109 d = 4;
110 break;
111 }
112 switch (sysconf.hcid[i]) {
113 case 1:
114 case 3:
115 dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j], 1));
116 if (dev) {
117 res = find_resource(dev, PCI_BASE_ADDRESS_0);
118 if (res) {
119 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][0],
120 res->base, gsi_base );
121 gsi_base+=d;
122 }
123 }
124 dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j]+1, 1));
125 if (dev) {
126 res = find_resource(dev, PCI_BASE_ADDRESS_0);
127 if (res) {
128 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][1],
129 res->base, gsi_base );
130 gsi_base+=d;
131
132 }
133 }
134 break;
135 }
136
137 j++;
138 }
139
140 }
141
142 current += acpi_create_madt_irqoverride( (acpi_madt_irqoverride_t *)
143 current, 0, 0, 2, 5 );
144 /* 0: mean bus 0--->ISA */
145 /* 0: PIC 0 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000146 /* 2: APIC 2 */
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000147 /* 5 mean: 0101 --> Edige-triggered, Active high*/
148
149
150 /* create all subtables for processors */
151 current = acpi_create_madt_lapic_nmis(current, 5, 1);
152 /* 1: LINT1 connect to NMI */
153
154
155 return current;
156}
157
Myles Watson3fe6b702009-10-09 20:13:43 +0000158unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) {
Rudolf Marek8db0cfe2009-02-03 22:37:22 +0000159 k8acpi_write_vars();
160 return (unsigned long) (acpigen_get_current());
161}
162
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000163unsigned long write_acpi_tables(unsigned long start)
164{
165 unsigned long current;
166 acpi_rsdp_t *rsdp;
167 acpi_rsdt_t *rsdt;
168 acpi_hpet_t *hpet;
169 acpi_madt_t *madt;
170 acpi_srat_t *srat;
171 acpi_slit_t *slit;
172 acpi_fadt_t *fadt;
173 acpi_facs_t *facs;
174 acpi_header_t *dsdt;
175 acpi_header_t *ssdt;
176 acpi_header_t *ssdtx;
Myles Watsonae608552010-04-09 03:41:23 +0000177 void *p;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000178
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000179 int i;
180
181 get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn
182
183 /* Align ACPI tables to 16byte */
184 start = ( start + 0x0f ) & -0x10;
185 current = start;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000186
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000187 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000188
189 /* We need at least an RSDP and an RSDT Table */
190 rsdp = (acpi_rsdp_t *) current;
191 current += sizeof(acpi_rsdp_t);
192 rsdt = (acpi_rsdt_t *) current;
193 current += sizeof(acpi_rsdt_t);
194
195 /* clear all table memory */
196 memset((void *)start, 0, current - start);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000197
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000198 acpi_write_rsdp(rsdp, rsdt, NULL);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000199 acpi_write_rsdt(rsdt);
200
201 /*
202 * We explicitly add these tables later on:
203 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000204 printk(BIOS_DEBUG, "ACPI: * HPET\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000205 hpet = (acpi_hpet_t *) current;
206 current += sizeof(acpi_hpet_t);
207 acpi_create_hpet(hpet);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000208 acpi_add_table(rsdp,hpet);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000209
210 /* If we want to use HPET Timers Linux wants an MADT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000211 printk(BIOS_DEBUG, "ACPI: * MADT\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000212 madt = (acpi_madt_t *) current;
213 acpi_create_madt(madt);
214 current+=madt->header.length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000215 acpi_add_table(rsdp,madt);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000216
217
218 /* SRAT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000219 printk(BIOS_DEBUG, "ACPI: * SRAT\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000220 srat = (acpi_srat_t *) current;
221 acpi_create_srat(srat);
222 current+=srat->header.length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000223 acpi_add_table(rsdp,srat);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000224
225 /* SLIT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000226 printk(BIOS_DEBUG, "ACPI: * SLIT\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000227 slit = (acpi_slit_t *) current;
228 acpi_create_slit(slit);
229 current+=slit->header.length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000230 acpi_add_table(rsdp,slit);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000231
232 /* SSDT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000233 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000234 ssdt = (acpi_header_t *)current;
Rudolf Marek8db0cfe2009-02-03 22:37:22 +0000235
236 acpi_create_ssdt_generator(ssdt, "DYNADATA");
237 current += ssdt->length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000238 acpi_add_table(rsdp, ssdt);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000239
Stefan Reinauer08670622009-06-30 15:17:49 +0000240#if CONFIG_ACPI_SSDTX_NUM >= 1
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000241
242 //same htio, but different position? We may have to copy, change HCIN, and recalculate the checknum and add_table
243
244 for(i=1;i<sysconf.hc_possible_num;i++) { // 0: is hc sblink
245 if((sysconf.pci1234[i] & 1) != 1 ) continue;
246 uint8_t c;
247 if(i<7) {
248 c = (uint8_t) ('4' + i - 1);
249 }
250 else {
251 c = (uint8_t) ('A' + i - 1 - 6);
252 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000253 printk(BIOS_DEBUG, "ACPI: * SSDT for PCI%c Aka hcid = %d\n", c, sysconf.hcid[i]); //pci0 and pci1 are in dsdt
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000254 current = ( current + 0x07) & -0x08;
255 ssdtx = (acpi_header_t *)current;
256 switch(sysconf.hcid[i]) {
257 case 1: //8132
Myles Watson565a2812010-03-24 22:02:53 +0000258 p = &AmlCode_ssdt2;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000259 break;
260 case 2: //8151
Myles Watson565a2812010-03-24 22:02:53 +0000261 p = &AmlCode_ssdt3;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000262 break;
263 case 3: //8131
Myles Watson565a2812010-03-24 22:02:53 +0000264 p = &AmlCode_ssdt4;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000265 break;
266 default:
Yinghai Lua5fc22f2006-12-20 20:21:05 +0000267 //HTX no io apic
Myles Watson565a2812010-03-24 22:02:53 +0000268 p = &AmlCode_ssdt5;
Yinghai Lua5fc22f2006-12-20 20:21:05 +0000269 break;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000270 }
Myles Watsonae608552010-04-09 03:41:23 +0000271 memcpy(ssdtx, p, sizeof(acpi_header_t));
272 current += ssdtx->length;
273 memcpy(ssdtx, p, ssdtx->length);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000274 update_ssdtx((void *)ssdtx, i);
275 ssdtx->checksum = 0;
276 ssdtx->checksum = acpi_checksum((unsigned char *)ssdtx,ssdtx->length);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000277 acpi_add_table(rsdp,ssdtx);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000278 }
279#endif
280
281 /* FACS */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000282 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000283 facs = (acpi_facs_t *) current;
284 current += sizeof(acpi_facs_t);
285 acpi_create_facs(facs);
286
287 /* DSDT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000288 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000289 dsdt = (acpi_header_t *)current;
Myles Watsonae608552010-04-09 03:41:23 +0000290 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
291 current += dsdt->length;
292 memcpy(dsdt, &AmlCode, dsdt->length);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000293 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000294
Zheng Bao7f20d732010-12-07 06:27:44 +0000295 /* FADT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000296 printk(BIOS_DEBUG, "ACPI: * FADT\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000297 fadt = (acpi_fadt_t *) current;
298 current += sizeof(acpi_fadt_t);
299
300 acpi_create_fadt(fadt,facs,dsdt);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000301 acpi_add_table(rsdp,fadt);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000302
303#if DUMP_ACPI_TABLES == 1
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000304 printk(BIOS_DEBUG, "rsdp\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000305 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
306
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000307 printk(BIOS_DEBUG, "rsdt\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000308 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
309
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000310 printk(BIOS_DEBUG, "madt\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000311 dump_mem(madt, ((void *)madt) + madt->header.length);
312
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000313 printk(BIOS_DEBUG, "srat\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000314 dump_mem(srat, ((void *)srat) + srat->header.length);
315
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000316 printk(BIOS_DEBUG, "slit\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000317 dump_mem(slit, ((void *)slit) + slit->header.length);
318
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000319 printk(BIOS_DEBUG, "ssdt\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000320 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
321
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000322 printk(BIOS_DEBUG, "fadt\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000323 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
324#endif
325
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000326 printk(BIOS_INFO, "ACPI: done.\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000327 return current;
328}
329