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>
20 #include "mb_sysconf.h"
22 #define DUMP_ACPI_TABLES 0
24 #if DUMP_ACPI_TABLES == 1
25 static void dump_mem(unsigned start, unsigned end)
29 print_debug("dump_mem:");
30 for(i=start;i<end;i++) {
32 printk_debug("\n%08x:", i);
34 printk_debug(" %02x", (unsigned char)*((unsigned char *)i));
40 extern unsigned char AmlCode[];
41 extern unsigned char AmlCode_ssdt[];
43 #if ACPI_SSDTX_NUM >= 1
44 extern unsigned char AmlCode_ssdt2[];
45 //extern unsigned char AmlCode_ssdt3[];
46 //extern unsigned char AmlCode_ssdt4[];
47 //extern unsigned char AmlCode_ssdt5[];
48 //extern unsigned char AmlCode_ssdt6[];
49 //extern unsigned char AmlCode_ssdt7[];
50 //extern unsigned char AmlCode_ssdt8[];
53 #define IO_APIC_ADDR 0xfec00000UL
55 unsigned long acpi_fill_madt(unsigned long current)
57 unsigned int gsi_base=0x18;
59 struct mb_sysconf_t *m;
63 /* create all subtables for processors */
64 current = acpi_create_madt_lapics(current);
66 /* Write 8111 IOAPIC */
67 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8111,
70 /* Write all 8131 IOAPICs */
74 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0]&0xff), 1));
76 res = find_resource(dev, PCI_BASE_ADDRESS_0);
78 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_1,
79 res->base, gsi_base );
84 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0] & 0xff)+1, 1));
86 res = find_resource(dev, PCI_BASE_ADDRESS_0);
88 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_2,
89 res->base, gsi_base );
95 current += acpi_create_madt_irqoverride( (acpi_madt_irqoverride_t *)
96 current, 0, 0, 2, 5 );
97 /* 0: mean bus 0--->ISA */
100 /* 5 mean: 0101 --> Edige-triggered, Active high*/
103 /* create all subtables for processors */
104 current = acpi_create_madt_lapic_nmis(current, 5, 1);
105 /* 1: LINT1 connect to NMI */
111 extern void get_bus_conf(void);
113 extern void update_ssdt(void *ssdt);
115 unsigned long write_acpi_tables(unsigned long start)
117 unsigned long current;
128 acpi_header_t *ssdtx;
130 unsigned char *AmlCode_ssdtx[HC_POSSIBLE_NUM];
134 get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn
136 /* Align ACPI tables to 16byte */
137 start = ( start + 0x0f ) & -0x10;
140 printk_info("ACPI: Writing ACPI tables at %lx...\n", start);
142 /* We need at least an RSDP and an RSDT Table */
143 rsdp = (acpi_rsdp_t *) current;
144 current += sizeof(acpi_rsdp_t);
145 rsdt = (acpi_rsdt_t *) current;
146 current += sizeof(acpi_rsdt_t);
148 /* clear all table memory */
149 memset((void *)start, 0, current - start);
151 acpi_write_rsdp(rsdp, rsdt);
152 acpi_write_rsdt(rsdt);
155 * We explicitly add these tables later on:
157 printk_debug("ACPI: * HPET\n");
158 hpet = (acpi_hpet_t *) current;
159 current += sizeof(acpi_hpet_t);
160 acpi_create_hpet(hpet);
161 acpi_add_table(rsdt,hpet);
163 /* If we want to use HPET Timers Linux wants an MADT */
164 printk_debug("ACPI: * MADT\n");
165 madt = (acpi_madt_t *) current;
166 acpi_create_madt(madt);
167 current+=madt->header.length;
168 acpi_add_table(rsdt,madt);
172 printk_debug("ACPI: * SRAT\n");
173 srat = (acpi_srat_t *) current;
174 acpi_create_srat(srat);
175 current+=srat->header.length;
176 acpi_add_table(rsdt,srat);
179 printk_debug("ACPI: * SLIT\n");
180 slit = (acpi_slit_t *) current;
181 acpi_create_slit(slit);
182 current+=slit->header.length;
183 acpi_add_table(rsdt,slit);
186 printk_debug("ACPI: * SSDT\n");
187 ssdt = (acpi_header_t *)current;
188 current += ((acpi_header_t *)AmlCode_ssdt)->length;
189 memcpy((void *)ssdt, (void *)AmlCode_ssdt, ((acpi_header_t *)AmlCode_ssdt)->length);
190 //Here you need to set value in pci1234, sblk and sbdn in get_bus_conf.c
191 update_ssdt((void*)ssdt);
192 /* recalculate checksum */
194 ssdt->checksum = acpi_checksum((unsigned char *)ssdt,ssdt->length);
195 acpi_add_table(rsdt,ssdt);
197 #if ACPI_SSDTX_NUM >= 1
198 // we need to make ssdt2 match to PCI2 in pci2.asl,... pci1234[1]
199 AmlCode_ssdtx[1] = AmlCode_ssdt2;
200 // AmlCode_ssdtx[2] = AmlCode_ssdt3;
201 // AmlCode_ssdtx[3] = AmlCode_ssdt4;
202 // AmlCode_ssdtx[4] = AmlCode_ssdt5;
203 // AmlCode_ssdtx[5] = AmlCode_ssdt6;
204 // AmlCode_ssdtx[6] = AmlCode_ssdt7;
205 // AmlCode_ssdtx[7] = AmlCode_ssdt8;
207 //same htio, but different possition? We may have to copy, change HCIN, and recalculate the checknum and add_table
209 for(i=1;i<sysconf.hc_possible_num;i++) { // 0: is hc sblink
210 if((sysconf.pci1234[i] & 1) != 1 ) continue;
211 printk_debug("ACPI: * SSDT for PCI%d\n", i+1); //pci0 and pci1 are in dsdt
212 ssdtx = (acpi_header_t *)current;
213 current += ((acpi_header_t *)AmlCode_ssdtx[i])->length;
214 memcpy((void *)ssdtx, (void *)AmlCode_ssdtx[i], ((acpi_header_t *)AmlCode_ssdtx[i])->length);
215 acpi_add_table(rsdt,ssdtx);
221 printk_debug("ACPI: * FACS\n");
222 facs = (acpi_facs_t *) current;
223 current += sizeof(acpi_facs_t);
224 acpi_create_facs(facs);
227 printk_debug("ACPI: * DSDT\n");
228 dsdt = (acpi_header_t *)current;
229 current += ((acpi_header_t *)AmlCode)->length;
230 memcpy((void *)dsdt,(void *)AmlCode, \
231 ((acpi_header_t *)AmlCode)->length);
232 printk_debug("ACPI: * DSDT @ %08x Length %x\n",dsdt,dsdt->length);
235 printk_debug("ACPI: * FADT\n");
236 fadt = (acpi_fadt_t *) current;
237 current += sizeof(acpi_fadt_t);
239 acpi_create_fadt(fadt,facs,dsdt);
240 acpi_add_table(rsdt,fadt);
242 #if DUMP_ACPI_TABLES == 1
243 printk_debug("rsdp\n");
244 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
246 printk_debug("rsdt\n");
247 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
249 printk_debug("madt\n");
250 dump_mem(madt, ((void *)madt) + madt->header.length);
252 printk_debug("srat\n");
253 dump_mem(srat, ((void *)srat) + srat->header.length);
255 printk_debug("slit\n");
256 dump_mem(slit, ((void *)slit) + slit->header.length);
258 printk_debug("ssdt\n");
259 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
261 printk_debug("fadt\n");
262 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
265 printk_info("ACPI: done.\n");