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 <device/pci.h>
15 #include <device/pci_ids.h>
16 #include <cpu/x86/msr.h>
17 #include <cpu/amd/mtrr.h>
18 #include <cpu/amd/amdk8_sysconf.h>
19 #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 acpi_header_t AmlCode;
42 #if CONFIG_ACPI_SSDTX_NUM >= 1
43 extern const acpi_header_t AmlCode_ssdt2;
44 extern const acpi_header_t AmlCode_ssdt3;
45 extern const acpi_header_t AmlCode_ssdt4;
48 #define IO_APIC_ADDR 0xfec00000UL
50 unsigned long acpi_fill_mcfg(unsigned long current)
56 unsigned long acpi_fill_madt(unsigned long current)
60 struct mb_sysconf_t *m;
64 /* create all subtables for processors */
65 current = acpi_create_madt_lapics(current);
67 /* Write 8111 IOAPIC */
68 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8111,
71 /* Write all 8131 IOAPICs */
75 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0]&0xff), 1));
77 res = find_resource(dev, PCI_BASE_ADDRESS_0);
79 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_1,
80 res->base, gsi_base );
85 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0] & 0xff)+1, 1));
87 res = find_resource(dev, PCI_BASE_ADDRESS_0);
89 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_2,
90 res->base, gsi_base );
98 for(i=1; i< sysconf.hc_possible_num; i++) {
100 if(!(sysconf.pci1234[i] & 0x1) ) continue;
101 // 8131 need to use +4
102 switch (sysconf.hcid[i]) {
110 switch (sysconf.hcid[i]) {
113 dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j], 1));
115 res = find_resource(dev, PCI_BASE_ADDRESS_0);
117 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][0],
118 res->base, gsi_base );
122 dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j]+1, 1));
124 res = find_resource(dev, PCI_BASE_ADDRESS_0);
126 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][1],
127 res->base, gsi_base );
138 current += acpi_create_madt_irqoverride( (acpi_madt_irqoverride_t *)
139 current, 0, 0, 2, 5 );
140 /* 0: mean bus 0--->ISA */
143 /* 5 mean: 0101 --> Edige-triggered, Active high*/
146 /* create all subtables for processors */
147 current = acpi_create_madt_lapic_nmis(current, 5, 1);
148 /* 1: LINT1 connect to NMI */
155 static void update_ssdtx(void *ssdtx, int i)
166 *PCI = (u8) ('4' + i - 1);
169 *PCI = (u8) ('A' + i - 1 - 6);
174 /* FIXME: need to update the GSI id in the ssdtx too */
178 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) {
180 return (unsigned long) (acpigen_get_current());
183 unsigned long write_acpi_tables(unsigned long start)
185 unsigned long current;
196 acpi_header_t *ssdtx;
197 acpi_header_t const *p;
201 get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn
203 /* Align ACPI tables to 16 bytes */
204 start = ( start + 0x0f) & -0x10;
207 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
209 /* We need at least an RSDP and an RSDT Table */
210 rsdp = (acpi_rsdp_t *) current;
211 current += sizeof(acpi_rsdp_t);
212 rsdt = (acpi_rsdt_t *) current;
213 current += sizeof(acpi_rsdt_t);
215 /* clear all table memory */
216 memset((void *)start, 0, current - start);
218 acpi_write_rsdp(rsdp, rsdt, NULL);
219 acpi_write_rsdt(rsdt);
222 * We explicitly add these tables later on:
224 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
225 hpet = (acpi_hpet_t *) current;
226 current += sizeof(acpi_hpet_t);
227 acpi_create_hpet(hpet);
228 acpi_add_table(rsdp, hpet);
230 /* If we want to use HPET Timers Linux wants an MADT */
231 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n", current);
232 madt = (acpi_madt_t *) current;
233 acpi_create_madt(madt);
234 current+=madt->header.length;
235 acpi_add_table(rsdp, madt);
238 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
239 srat = (acpi_srat_t *) current;
240 acpi_create_srat(srat);
241 current+=srat->header.length;
242 acpi_add_table(rsdp, srat);
245 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
246 slit = (acpi_slit_t *) current;
247 acpi_create_slit(slit);
248 current+=slit->header.length;
249 acpi_add_table(rsdp, slit);
252 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
253 ssdt = (acpi_header_t *)current;
255 acpi_create_ssdt_generator(ssdt, "DYNADATA");
256 current += ssdt->length;
257 acpi_add_table(rsdp, ssdt);
259 #if CONFIG_ACPI_SSDTX_NUM >= 1
261 //same htio, but different position? We may have to copy, change HCIN, and recalculate the checknum and add_table
263 for(i=1;i<sysconf.hc_possible_num;i++) { // 0: is hc sblink
264 if((sysconf.pci1234[i] & 1) != 1 ) continue;
267 c = (u8) ('4' + i - 1);
270 c = (u8) ('A' + i - 1 - 6);
272 current = ( current + 0x07) & -0x08;
273 printk(BIOS_DEBUG, "ACPI: * SSDT for PCI%c Aka hcid = %d\n", c, sysconf.hcid[i]); //pci0 and pci1 are in dsdt
274 ssdtx = (acpi_header_t *)current;
275 switch(sysconf.hcid[i]) {
288 current += p->length;
289 memcpy((void *)ssdtx, (void *)p, ((acpi_header_t *)p)->length);
290 update_ssdtx((void *)ssdtx, i);
292 ssdtx->checksum = acpi_checksum((u8 *)ssdtx, ssdtx->length);
293 acpi_add_table(rsdp, ssdtx);
298 printk(BIOS_DEBUG, "ACPI: * FACS\n");
299 facs = (acpi_facs_t *) current;
300 current += sizeof(acpi_facs_t);
301 acpi_create_facs(facs);
304 printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current);
305 dsdt = (acpi_header_t *)current;
306 current += AmlCode.length;
307 memcpy((void *)dsdt, &AmlCode, AmlCode.length);
308 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, dsdt->length);
311 printk(BIOS_DEBUG, "ACPI: * FADT at %lx\n", current);
312 fadt = (acpi_fadt_t *) current;
313 current += sizeof(acpi_fadt_t);
315 acpi_create_fadt(fadt, facs, dsdt);
316 acpi_add_table(rsdp, fadt);
318 #if DUMP_ACPI_TABLES == 1
319 printk(BIOS_DEBUG, "rsdp\n");
320 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
322 printk(BIOS_DEBUG, "rsdt\n");
323 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
325 printk(BIOS_DEBUG, "madt\n");
326 dump_mem(madt, ((void *)madt) + madt->header.length);
328 printk(BIOS_DEBUG, "srat\n");
329 dump_mem(srat, ((void *)srat) + srat->header.length);
331 printk(BIOS_DEBUG, "slit\n");
332 dump_mem(slit, ((void *)slit) + slit->header.length);
334 printk(BIOS_DEBUG, "ssdt\n");
335 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
337 printk(BIOS_DEBUG, "fadt\n");
338 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
341 printk(BIOS_INFO, "ACPI: done.\n");