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(unsigned start, unsigned end)
30 print_debug("dump_mem:");
31 for(i=start;i<end;i++) {
33 printk_debug("\n%08x:", i);
35 printk_debug(" %02x", (unsigned char)*((unsigned char *)i));
41 extern unsigned char AmlCode[];
42 #if ACPI_SSDTX_NUM >= 1
43 extern unsigned char AmlCode_ssdt2[];
44 extern unsigned char AmlCode_ssdt3[];
45 extern unsigned char 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)
58 unsigned int gsi_base=0x18;
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
103 switch (sysconf.hcid[i]) {
111 switch (sysconf.hcid[i]) {
114 dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j], 1));
116 res = find_resource(dev, PCI_BASE_ADDRESS_0);
118 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][0],
119 res->base, gsi_base );
123 dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j]+1, 1));
125 res = find_resource(dev, PCI_BASE_ADDRESS_0);
127 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][1],
128 res->base, gsi_base );
141 current += acpi_create_madt_irqoverride( (acpi_madt_irqoverride_t *)
142 current, 0, 0, 2, 5 );
143 /* 0: mean bus 0--->ISA */
146 /* 5 mean: 0101 --> Edige-triggered, Active high*/
149 /* create all subtables for processors */
150 current = acpi_create_madt_lapic_nmis(current, 5, 1);
151 /* 1: LINT1 connect to NMI */
157 extern void get_bus_conf(void);
159 void update_ssdtx(void *ssdtx, int i)
170 *PCI = (uint8_t) ('4' + i - 1);
173 *PCI = (uint8_t) ('A' + i - 1 - 6);
176 *UID = (uint8_t) (i+3);
178 /* FIXME: need to update the GSI id in the ssdtx too */
182 unsigned long acpi_fill_ssdt_generator(unsigned long current, char *oem_table_id) {
184 return (unsigned long) (acpigen_get_current());
187 unsigned long write_acpi_tables(unsigned long start)
189 unsigned long current;
200 acpi_header_t *ssdtx;
203 unsigned char *AmlCode_ssdtx[HC_POSSIBLE_NUM];
207 get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn
209 /* Align ACPI tables to 16byte */
210 start = ( start + 0x0f ) & -0x10;
213 printk_info("ACPI: Writing ACPI tables at %lx...\n", start);
215 /* We need at least an RSDP and an RSDT Table */
216 rsdp = (acpi_rsdp_t *) current;
217 current += sizeof(acpi_rsdp_t);
218 rsdt = (acpi_rsdt_t *) current;
219 current += sizeof(acpi_rsdt_t);
221 /* clear all table memory */
222 memset((void *)start, 0, current - start);
224 acpi_write_rsdp(rsdp, rsdt);
225 acpi_write_rsdt(rsdt);
228 * We explicitly add these tables later on:
230 printk_debug("ACPI: * HPET\n");
231 hpet = (acpi_hpet_t *) current;
232 current += sizeof(acpi_hpet_t);
233 acpi_create_hpet(hpet);
234 acpi_add_table(rsdt,hpet);
236 /* If we want to use HPET Timers Linux wants an MADT */
237 printk_debug("ACPI: * MADT\n");
238 madt = (acpi_madt_t *) current;
239 acpi_create_madt(madt);
240 current+=madt->header.length;
241 acpi_add_table(rsdt,madt);
245 printk_debug("ACPI: * SRAT\n");
246 srat = (acpi_srat_t *) current;
247 acpi_create_srat(srat);
248 current+=srat->header.length;
249 acpi_add_table(rsdt,srat);
252 printk_debug("ACPI: * SLIT\n");
253 slit = (acpi_slit_t *) current;
254 acpi_create_slit(slit);
255 current+=slit->header.length;
256 acpi_add_table(rsdt,slit);
259 printk_debug("ACPI: * SSDT\n");
260 ssdt = (acpi_header_t *)current;
262 acpi_create_ssdt_generator(ssdt, "DYNADATA");
263 current += ssdt->length;
264 acpi_add_table(rsdt, ssdt);
266 #if ACPI_SSDTX_NUM >= 1
268 //same htio, but different position? We may have to copy, change HCIN, and recalculate the checknum and add_table
270 for(i=1;i<sysconf.hc_possible_num;i++) { // 0: is hc sblink
271 if((sysconf.pci1234[i] & 1) != 1 ) continue;
274 c = (uint8_t) ('4' + i - 1);
277 c = (uint8_t) ('A' + i - 1 - 6);
279 printk_debug("ACPI: * SSDT for PCI%c Aka hcid = %d\n", c, sysconf.hcid[i]); //pci0 and pci1 are in dsdt
280 current = ( current + 0x07) & -0x08;
281 ssdtx = (acpi_header_t *)current;
282 switch(sysconf.hcid[i]) {
295 current += ((acpi_header_t *)p)->length;
296 memcpy((void *)ssdtx, (void *)p, ((acpi_header_t *)p)->length);
297 update_ssdtx((void *)ssdtx, i);
299 ssdtx->checksum = acpi_checksum((unsigned char *)ssdtx,ssdtx->length);
300 acpi_add_table(rsdt,ssdtx);
305 printk_debug("ACPI: * FACS\n");
306 facs = (acpi_facs_t *) current;
307 current += sizeof(acpi_facs_t);
308 acpi_create_facs(facs);
311 printk_debug("ACPI: * DSDT\n");
312 dsdt = (acpi_header_t *)current;
313 current += ((acpi_header_t *)AmlCode)->length;
314 memcpy((void *)dsdt,(void *)AmlCode, \
315 ((acpi_header_t *)AmlCode)->length);
316 printk_debug("ACPI: * DSDT @ %08x Length %x\n",dsdt,dsdt->length);
319 printk_debug("ACPI: * FADT\n");
320 fadt = (acpi_fadt_t *) current;
321 current += sizeof(acpi_fadt_t);
323 acpi_create_fadt(fadt,facs,dsdt);
324 acpi_add_table(rsdt,fadt);
326 #if DUMP_ACPI_TABLES == 1
327 printk_debug("rsdp\n");
328 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
330 printk_debug("rsdt\n");
331 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
333 printk_debug("madt\n");
334 dump_mem(madt, ((void *)madt) + madt->header.length);
336 printk_debug("srat\n");
337 dump_mem(srat, ((void *)srat) + srat->header.length);
339 printk_debug("slit\n");
340 dump_mem(slit, ((void *)slit) + slit->header.length);
342 printk_debug("ssdt\n");
343 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
345 printk_debug("fadt\n");
346 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
349 printk_info("ACPI: done.\n");