2 * Island Aruma ACPI support
3 * written by Stefan Reinauer <stepan@openbios.org>
4 * (C) 2005 Stefan Reinauer
8 * 2005.9 yhlu modify that to more dynamic for AMD Opteron Based MB
11 #include <console/console.h>
13 #include <arch/acpi.h>
14 #include <arch/ioapic.h>
15 #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>
20 #include "northbridge/amd/amdk8/amdk8_acpi.h"
21 #include "mb_sysconf.h"
23 #define DUMP_ACPI_TABLES 0
25 #if DUMP_ACPI_TABLES == 1
26 static void dump_mem(u32 start, u32 end)
30 print_debug("dump_mem:");
31 for(i=start;i<end;i++) {
33 printk(BIOS_DEBUG, "\n%08x:", i);
35 printk(BIOS_DEBUG, " %02x", (unsigned char)*((unsigned char *)i));
41 extern const unsigned char AmlCode[];
42 #if CONFIG_ACPI_SSDTX_NUM >= 1
43 extern const unsigned char AmlCode_ssdt2[];
44 extern const unsigned char AmlCode_ssdt3[];
45 extern const unsigned char AmlCode_ssdt4[];
48 unsigned long acpi_fill_mcfg(unsigned long current)
54 unsigned long acpi_fill_madt(unsigned long current)
58 struct mb_sysconf_t *m;
62 /* create all subtables for processors */
63 current = acpi_create_madt_lapics(current);
65 /* Write 8111 IOAPIC */
66 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8111,
69 /* Write all 8131 IOAPICs */
73 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0]&0xff), 1));
75 res = find_resource(dev, PCI_BASE_ADDRESS_0);
77 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_1,
78 res->base, gsi_base );
83 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0] & 0xff)+1, 1));
85 res = find_resource(dev, PCI_BASE_ADDRESS_0);
87 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_2,
88 res->base, gsi_base );
96 for(i=1; i< sysconf.hc_possible_num; i++) {
98 if(!(sysconf.pci1234[i] & 0x1) ) continue;
99 // 8131 need to use +4
100 switch (sysconf.hcid[i]) {
108 switch (sysconf.hcid[i]) {
111 dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j], 1));
113 res = find_resource(dev, PCI_BASE_ADDRESS_0);
115 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][0],
116 res->base, gsi_base );
120 dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j]+1, 1));
122 res = find_resource(dev, PCI_BASE_ADDRESS_0);
124 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][1],
125 res->base, gsi_base );
136 current += acpi_create_madt_irqoverride( (acpi_madt_irqoverride_t *)
137 current, 0, 0, 2, 5 );
138 /* 0: mean bus 0--->ISA */
141 /* 5 mean: 0101 --> Edige-triggered, Active high*/
144 /* create all subtables for processors */
145 current = acpi_create_madt_lapic_nmis(current, 5, 1);
146 /* 1: LINT1 connect to NMI */
151 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) {
153 return (unsigned long) (acpigen_get_current());
156 unsigned long write_acpi_tables(unsigned long start)
158 unsigned long current;
169 acpi_header_t *ssdtx;
174 get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn
176 /* Align ACPI tables to 16 bytes */
177 start = ( start + 0x0f) & -0x10;
180 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
182 /* We need at least an RSDP and an RSDT Table */
183 rsdp = (acpi_rsdp_t *) current;
184 current += sizeof(acpi_rsdp_t);
185 rsdt = (acpi_rsdt_t *) current;
186 current += sizeof(acpi_rsdt_t);
188 /* clear all table memory */
189 memset((void *)start, 0, current - start);
191 acpi_write_rsdp(rsdp, rsdt, NULL);
192 acpi_write_rsdt(rsdt);
195 * We explicitly add these tables later on:
197 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
198 hpet = (acpi_hpet_t *) current;
199 current += sizeof(acpi_hpet_t);
200 acpi_create_hpet(hpet);
201 acpi_add_table(rsdp, hpet);
203 /* If we want to use HPET Timers Linux wants an MADT */
204 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n", current);
205 madt = (acpi_madt_t *) current;
206 acpi_create_madt(madt);
207 current+=madt->header.length;
208 acpi_add_table(rsdp, madt);
211 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
212 srat = (acpi_srat_t *) current;
213 acpi_create_srat(srat);
214 current+=srat->header.length;
215 acpi_add_table(rsdp, srat);
218 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
219 slit = (acpi_slit_t *) current;
220 acpi_create_slit(slit);
221 current+=slit->header.length;
222 acpi_add_table(rsdp, slit);
225 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
226 ssdt = (acpi_header_t *)current;
228 acpi_create_ssdt_generator(ssdt, "DYNADATA");
229 current += ssdt->length;
230 acpi_add_table(rsdp, ssdt);
232 #if CONFIG_ACPI_SSDTX_NUM >= 1
234 //same htio, but different position? We may have to copy, change HCIN, and recalculate the checknum and add_table
236 for(i=1;i<sysconf.hc_possible_num;i++) { // 0: is hc sblink
237 if((sysconf.pci1234[i] & 1) != 1 ) continue;
240 c = (u8) ('4' + i - 1);
243 c = (u8) ('A' + i - 1 - 6);
245 current = ( current + 0x07) & -0x08;
246 printk(BIOS_DEBUG, "ACPI: * SSDT for PCI%c Aka hcid = %d\n", c, sysconf.hcid[i]); //pci0 and pci1 are in dsdt
247 ssdtx = (acpi_header_t *)current;
248 switch(sysconf.hcid[i]) {
261 memcpy(ssdtx, p, sizeof(acpi_header_t));
262 current += ssdtx->length;
263 memcpy(ssdtx, p, ssdtx->length);
264 update_ssdtx((void *)ssdtx, i);
266 ssdtx->checksum = acpi_checksum((u8 *)ssdtx, ssdtx->length);
267 acpi_add_table(rsdp, ssdtx);
272 printk(BIOS_DEBUG, "ACPI: * FACS\n");
273 facs = (acpi_facs_t *) current;
274 current += sizeof(acpi_facs_t);
275 acpi_create_facs(facs);
278 printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current);
279 dsdt = (acpi_header_t *)current;
280 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
281 current += dsdt->length;
282 memcpy(dsdt, &AmlCode, dsdt->length);
283 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, dsdt->length);
286 printk(BIOS_DEBUG, "ACPI: * FADT at %lx\n", current);
287 fadt = (acpi_fadt_t *) current;
288 current += sizeof(acpi_fadt_t);
290 acpi_create_fadt(fadt, facs, dsdt);
291 acpi_add_table(rsdp, fadt);
293 #if DUMP_ACPI_TABLES == 1
294 printk(BIOS_DEBUG, "rsdp\n");
295 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
297 printk(BIOS_DEBUG, "rsdt\n");
298 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
300 printk(BIOS_DEBUG, "madt\n");
301 dump_mem(madt, ((void *)madt) + madt->header.length);
303 printk(BIOS_DEBUG, "srat\n");
304 dump_mem(srat, ((void *)srat) + srat->header.length);
306 printk(BIOS_DEBUG, "slit\n");
307 dump_mem(slit, ((void *)slit) + slit->header.length);
309 printk(BIOS_DEBUG, "ssdt\n");
310 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
312 printk(BIOS_DEBUG, "fadt\n");
313 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
316 printk(BIOS_INFO, "ACPI: done.\n");