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[];
43 #if CONFIG_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[];
50 #define IO_APIC_ADDR 0xfec00000UL
52 unsigned long acpi_fill_mcfg(unsigned long current)
59 unsigned long acpi_fill_madt(unsigned long current)
61 unsigned int gsi_base=0x18;
63 struct mb_sysconf_t *m;
67 /* create all subtables for processors */
68 current = acpi_create_madt_lapics(current);
70 /* Write 8111 IOAPIC */
71 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8111,
74 /* Write all 8131 IOAPICs */
78 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0]&0xff), 1));
80 res = find_resource(dev, PCI_BASE_ADDRESS_0);
82 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_1,
83 res->base, gsi_base );
88 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0] & 0xff)+1, 1));
90 res = find_resource(dev, PCI_BASE_ADDRESS_0);
92 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_2,
93 res->base, gsi_base );
101 for(i=1; i< sysconf.hc_possible_num; i++) {
103 if(!(sysconf.pci1234[i] & 0x1) ) continue;
104 // 8131 need to use +4
106 switch (sysconf.hcid[i]) {
114 switch (sysconf.hcid[i]) {
117 dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j], 1));
119 res = find_resource(dev, PCI_BASE_ADDRESS_0);
121 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][0],
122 res->base, gsi_base );
126 dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j]+1, 1));
128 res = find_resource(dev, PCI_BASE_ADDRESS_0);
130 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][1],
131 res->base, gsi_base );
144 current += acpi_create_madt_irqoverride( (acpi_madt_irqoverride_t *)
145 current, 0, 0, 2, 5 );
146 /* 0: mean bus 0--->ISA */
149 /* 5 mean: 0101 --> Edige-triggered, Active high*/
152 /* create all subtables for processors */
153 current = acpi_create_madt_lapic_nmis(current, 5, 1);
154 /* 1: LINT1 connect to NMI */
160 extern void get_bus_conf(void);
162 static void update_ssdtx(void *ssdtx, int i)
173 *PCI = (uint8_t) ('4' + i - 1);
176 *PCI = (uint8_t) ('A' + i - 1 - 6);
179 *UID = (uint8_t) (i+3);
181 /* FIXME: need to update the GSI id in the ssdtx too */
185 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) {
187 return (unsigned long) (acpigen_get_current());
190 unsigned long write_acpi_tables(unsigned long start)
192 unsigned long current;
203 acpi_header_t *ssdtx;
208 get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn
210 /* Align ACPI tables to 16byte */
211 start = ( start + 0x0f ) & -0x10;
214 printk_info("ACPI: Writing ACPI tables at %lx...\n", start);
216 /* We need at least an RSDP and an RSDT Table */
217 rsdp = (acpi_rsdp_t *) current;
218 current += sizeof(acpi_rsdp_t);
219 rsdt = (acpi_rsdt_t *) current;
220 current += sizeof(acpi_rsdt_t);
222 /* clear all table memory */
223 memset((void *)start, 0, current - start);
225 acpi_write_rsdp(rsdp, rsdt, NULL);
226 acpi_write_rsdt(rsdt);
229 * We explicitly add these tables later on:
231 printk_debug("ACPI: * HPET\n");
232 hpet = (acpi_hpet_t *) current;
233 current += sizeof(acpi_hpet_t);
234 acpi_create_hpet(hpet);
235 acpi_add_table(rsdp,hpet);
237 /* If we want to use HPET Timers Linux wants an MADT */
238 printk_debug("ACPI: * MADT\n");
239 madt = (acpi_madt_t *) current;
240 acpi_create_madt(madt);
241 current+=madt->header.length;
242 acpi_add_table(rsdp,madt);
246 printk_debug("ACPI: * SRAT\n");
247 srat = (acpi_srat_t *) current;
248 acpi_create_srat(srat);
249 current+=srat->header.length;
250 acpi_add_table(rsdp,srat);
253 printk_debug("ACPI: * SLIT\n");
254 slit = (acpi_slit_t *) current;
255 acpi_create_slit(slit);
256 current+=slit->header.length;
257 acpi_add_table(rsdp,slit);
260 printk_debug("ACPI: * SSDT\n");
261 ssdt = (acpi_header_t *)current;
263 acpi_create_ssdt_generator(ssdt, "DYNADATA");
264 current += ssdt->length;
265 acpi_add_table(rsdp, ssdt);
267 #if CONFIG_ACPI_SSDTX_NUM >= 1
269 //same htio, but different position? We may have to copy, change HCIN, and recalculate the checknum and add_table
271 for(i=1;i<sysconf.hc_possible_num;i++) { // 0: is hc sblink
272 if((sysconf.pci1234[i] & 1) != 1 ) continue;
275 c = (uint8_t) ('4' + i - 1);
278 c = (uint8_t) ('A' + i - 1 - 6);
280 printk_debug("ACPI: * SSDT for PCI%c Aka hcid = %d\n", c, sysconf.hcid[i]); //pci0 and pci1 are in dsdt
281 current = ( current + 0x07) & -0x08;
282 ssdtx = (acpi_header_t *)current;
283 switch(sysconf.hcid[i]) {
298 current += ((acpi_header_t *)p)->length;
299 memcpy((void *)ssdtx, (void *)p, ((acpi_header_t *)p)->length);
300 update_ssdtx((void *)ssdtx, i);
302 ssdtx->checksum = acpi_checksum((unsigned char *)ssdtx,ssdtx->length);
303 acpi_add_table(rsdp,ssdtx);
308 printk_debug("ACPI: * FACS\n");
309 facs = (acpi_facs_t *) current;
310 current += sizeof(acpi_facs_t);
311 acpi_create_facs(facs);
314 printk_debug("ACPI: * DSDT\n");
315 dsdt = (acpi_header_t *)current;
316 current += ((acpi_header_t *)AmlCode)->length;
317 memcpy((void *)dsdt,(void *)AmlCode, \
318 ((acpi_header_t *)AmlCode)->length);
319 printk_debug("ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length);
322 printk_debug("ACPI: * FADT\n");
323 fadt = (acpi_fadt_t *) current;
324 current += sizeof(acpi_fadt_t);
326 acpi_create_fadt(fadt,facs,dsdt);
327 acpi_add_table(rsdp,fadt);
329 #if DUMP_ACPI_TABLES == 1
330 printk_debug("rsdp\n");
331 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
333 printk_debug("rsdt\n");
334 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
336 printk_debug("madt\n");
337 dump_mem(madt, ((void *)madt) + madt->header.length);
339 printk_debug("srat\n");
340 dump_mem(srat, ((void *)srat) + srat->header.length);
342 printk_debug("slit\n");
343 dump_mem(slit, ((void *)slit) + slit->header.length);
345 printk_debug("ssdt\n");
346 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
348 printk_debug("fadt\n");
349 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
352 printk_info("ACPI: done.\n");