blob: a9eac0df5f97ce4fabddc08f447ce73302ae5b34 [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
Myles Watsonae608552010-04-09 03:41:23 +000023extern const unsigned char AmlCode[];
Yinghai Luc34e3ab2006-10-12 00:58:20 +000024
Stefan Reinauer08670622009-06-30 15:17:49 +000025#if CONFIG_ACPI_SSDTX_NUM >= 1
Myles Watsonae608552010-04-09 03:41:23 +000026extern const unsigned char AmlCode_ssdt2[];
27extern const unsigned char AmlCode_ssdt3[];
28extern const unsigned char AmlCode_ssdt4[];
29extern const unsigned char AmlCode_ssdt5[];
Yinghai Luc34e3ab2006-10-12 00:58:20 +000030#endif
31
Stefan Reinauer2cb70142007-11-04 16:50:27 +000032unsigned long acpi_fill_mcfg(unsigned long current)
33{
34 /* Just a dummy */
35 return current;
36}
37
38
Yinghai Luc34e3ab2006-10-12 00:58:20 +000039unsigned long acpi_fill_madt(unsigned long current)
40{
41 unsigned int gsi_base=0x18;
42
43 struct mb_sysconf_t *m;
44
45 m = sysconf.mb;
Stefan Reinauer14e22772010-04-27 06:56:47 +000046
Yinghai Luc34e3ab2006-10-12 00:58:20 +000047 /* create all subtables for processors */
48 current = acpi_create_madt_lapics(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +000049
Yinghai Luc34e3ab2006-10-12 00:58:20 +000050 /* Write 8111 IOAPIC */
51 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8111,
52 IO_APIC_ADDR, 0);
53
54 /* Write all 8131 IOAPICs */
55 {
56 device_t dev;
57 struct resource *res;
58 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0]&0xff), 1));
59 if (dev) {
60 res = find_resource(dev, PCI_BASE_ADDRESS_0);
61 if (res) {
62 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_1,
63 res->base, gsi_base );
64 gsi_base+=4;
65
66 }
67 }
68 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0] & 0xff)+1, 1));
69 if (dev) {
70 res = find_resource(dev, PCI_BASE_ADDRESS_0);
71 if (res) {
72 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_2,
73 res->base, gsi_base );
74 gsi_base+=4;
75 }
76 }
77
78 int i;
79 int j = 0;
80
81 for(i=1; i< sysconf.hc_possible_num; i++) {
Stefan Reinauer50776fa2010-03-17 04:40:15 +000082 unsigned d = 0;
Yinghai Luc34e3ab2006-10-12 00:58:20 +000083 if(!(sysconf.pci1234[i] & 0x1) ) continue;
84 // 8131 need to use +4
Stefan Reinauer14e22772010-04-27 06:56:47 +000085
Yinghai Luc34e3ab2006-10-12 00:58:20 +000086 switch (sysconf.hcid[i]) {
87 case 1:
88 d = 7;
89 break;
90 case 3:
91 d = 4;
92 break;
93 }
94 switch (sysconf.hcid[i]) {
95 case 1:
96 case 3:
97 dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j], 1));
98 if (dev) {
99 res = find_resource(dev, PCI_BASE_ADDRESS_0);
100 if (res) {
101 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][0],
102 res->base, gsi_base );
103 gsi_base+=d;
104 }
105 }
106 dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j]+1, 1));
107 if (dev) {
108 res = find_resource(dev, PCI_BASE_ADDRESS_0);
109 if (res) {
110 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][1],
111 res->base, gsi_base );
112 gsi_base+=d;
113
114 }
115 }
116 break;
117 }
118
119 j++;
120 }
121
122 }
123
124 current += acpi_create_madt_irqoverride( (acpi_madt_irqoverride_t *)
125 current, 0, 0, 2, 5 );
126 /* 0: mean bus 0--->ISA */
127 /* 0: PIC 0 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000128 /* 2: APIC 2 */
Kyösti Mälkkid8747572014-06-26 05:30:54 +0300129 /* 5 mean: 0101 --> Edge-triggered, Active high*/
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000130
131
132 /* create all subtables for processors */
133 current = acpi_create_madt_lapic_nmis(current, 5, 1);
134 /* 1: LINT1 connect to NMI */
135
136
137 return current;
138}
139
Myles Watson3fe6b702009-10-09 20:13:43 +0000140unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) {
Rudolf Marek8db0cfe2009-02-03 22:37:22 +0000141 k8acpi_write_vars();
142 return (unsigned long) (acpigen_get_current());
143}
144
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000145unsigned long write_acpi_tables(unsigned long start)
146{
147 unsigned long current;
148 acpi_rsdp_t *rsdp;
149 acpi_rsdt_t *rsdt;
150 acpi_hpet_t *hpet;
151 acpi_madt_t *madt;
152 acpi_srat_t *srat;
153 acpi_slit_t *slit;
154 acpi_fadt_t *fadt;
155 acpi_facs_t *facs;
156 acpi_header_t *dsdt;
157 acpi_header_t *ssdt;
158 acpi_header_t *ssdtx;
Myles Watsonae608552010-04-09 03:41:23 +0000159 void *p;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000160
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000161 int i;
162
163 get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn
164
165 /* Align ACPI tables to 16byte */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200166 start = ALIGN(start, 16);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000167 current = start;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000168
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000169 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000170
171 /* We need at least an RSDP and an RSDT Table */
172 rsdp = (acpi_rsdp_t *) current;
173 current += sizeof(acpi_rsdp_t);
174 rsdt = (acpi_rsdt_t *) current;
175 current += sizeof(acpi_rsdt_t);
176
177 /* clear all table memory */
178 memset((void *)start, 0, current - start);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000179
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000180 acpi_write_rsdp(rsdp, rsdt, NULL);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000181 acpi_write_rsdt(rsdt);
182
183 /*
184 * We explicitly add these tables later on:
185 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000186 printk(BIOS_DEBUG, "ACPI: * HPET\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000187 hpet = (acpi_hpet_t *) current;
188 current += sizeof(acpi_hpet_t);
189 acpi_create_hpet(hpet);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000190 acpi_add_table(rsdp,hpet);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000191
192 /* If we want to use HPET Timers Linux wants an MADT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000193 printk(BIOS_DEBUG, "ACPI: * MADT\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000194 madt = (acpi_madt_t *) current;
195 acpi_create_madt(madt);
196 current+=madt->header.length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000197 acpi_add_table(rsdp,madt);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000198
199
200 /* SRAT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000201 printk(BIOS_DEBUG, "ACPI: * SRAT\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000202 srat = (acpi_srat_t *) current;
203 acpi_create_srat(srat);
204 current+=srat->header.length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000205 acpi_add_table(rsdp,srat);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000206
207 /* SLIT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000208 printk(BIOS_DEBUG, "ACPI: * SLIT\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000209 slit = (acpi_slit_t *) current;
210 acpi_create_slit(slit);
211 current+=slit->header.length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000212 acpi_add_table(rsdp,slit);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000213
214 /* SSDT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000215 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000216 ssdt = (acpi_header_t *)current;
Rudolf Marek8db0cfe2009-02-03 22:37:22 +0000217
Stefan Reinauera251dee2011-10-13 01:18:29 +0200218 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
Rudolf Marek8db0cfe2009-02-03 22:37:22 +0000219 current += ssdt->length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000220 acpi_add_table(rsdp, ssdt);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000221
Stefan Reinauer08670622009-06-30 15:17:49 +0000222#if CONFIG_ACPI_SSDTX_NUM >= 1
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000223
224 //same htio, but different position? We may have to copy, change HCIN, and recalculate the checknum and add_table
225
226 for(i=1;i<sysconf.hc_possible_num;i++) { // 0: is hc sblink
227 if((sysconf.pci1234[i] & 1) != 1 ) continue;
228 uint8_t c;
229 if(i<7) {
230 c = (uint8_t) ('4' + i - 1);
231 }
232 else {
233 c = (uint8_t) ('A' + i - 1 - 6);
234 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000235 printk(BIOS_DEBUG, "ACPI: * SSDT for PCI%c Aka hcid = %d\n", c, sysconf.hcid[i]); //pci0 and pci1 are in dsdt
Patrick Georgi26b00e62012-04-20 19:19:47 +0200236 current = ALIGN(current, 8);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000237 ssdtx = (acpi_header_t *)current;
238 switch(sysconf.hcid[i]) {
239 case 1: //8132
Myles Watson565a2812010-03-24 22:02:53 +0000240 p = &AmlCode_ssdt2;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000241 break;
242 case 2: //8151
Myles Watson565a2812010-03-24 22:02:53 +0000243 p = &AmlCode_ssdt3;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000244 break;
245 case 3: //8131
Myles Watson565a2812010-03-24 22:02:53 +0000246 p = &AmlCode_ssdt4;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000247 break;
248 default:
Yinghai Lua5fc22f2006-12-20 20:21:05 +0000249 //HTX no io apic
Myles Watson565a2812010-03-24 22:02:53 +0000250 p = &AmlCode_ssdt5;
Yinghai Lua5fc22f2006-12-20 20:21:05 +0000251 break;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000252 }
Myles Watsonae608552010-04-09 03:41:23 +0000253 memcpy(ssdtx, p, sizeof(acpi_header_t));
254 current += ssdtx->length;
255 memcpy(ssdtx, p, ssdtx->length);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000256 update_ssdtx((void *)ssdtx, i);
257 ssdtx->checksum = 0;
258 ssdtx->checksum = acpi_checksum((unsigned char *)ssdtx,ssdtx->length);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000259 acpi_add_table(rsdp,ssdtx);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000260 }
261#endif
262
263 /* FACS */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000264 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000265 facs = (acpi_facs_t *) current;
266 current += sizeof(acpi_facs_t);
267 acpi_create_facs(facs);
268
269 /* DSDT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000270 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000271 dsdt = (acpi_header_t *)current;
Myles Watsonae608552010-04-09 03:41:23 +0000272 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
273 current += dsdt->length;
274 memcpy(dsdt, &AmlCode, dsdt->length);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000275 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000276
Zheng Bao7f20d732010-12-07 06:27:44 +0000277 /* FADT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000278 printk(BIOS_DEBUG, "ACPI: * FADT\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000279 fadt = (acpi_fadt_t *) current;
280 current += sizeof(acpi_fadt_t);
281
282 acpi_create_fadt(fadt,facs,dsdt);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000283 acpi_add_table(rsdp,fadt);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000284
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000285 printk(BIOS_INFO, "ACPI: done.\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000286 return current;
287}
288