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 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, 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;
206 unsigned char *AmlCode_ssdtx[HC_POSSIBLE_NUM];
210 get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn
212 /* Align ACPI tables to 16byte */
213 start = ( start + 0x0f ) & -0x10;
216 printk_info("ACPI: Writing ACPI tables at %lx...\n", start);
218 /* We need at least an RSDP and an RSDT Table */
219 rsdp = (acpi_rsdp_t *) current;
220 current += sizeof(acpi_rsdp_t);
221 rsdt = (acpi_rsdt_t *) current;
222 current += sizeof(acpi_rsdt_t);
224 /* clear all table memory */
225 memset((void *)start, 0, current - start);
227 acpi_write_rsdp(rsdp, rsdt);
228 acpi_write_rsdt(rsdt);
231 * We explicitly add these tables later on:
233 printk_debug("ACPI: * HPET\n");
234 hpet = (acpi_hpet_t *) current;
235 current += sizeof(acpi_hpet_t);
236 acpi_create_hpet(hpet);
237 acpi_add_table(rsdt,hpet);
239 /* If we want to use HPET Timers Linux wants an MADT */
240 printk_debug("ACPI: * MADT\n");
241 madt = (acpi_madt_t *) current;
242 acpi_create_madt(madt);
243 current+=madt->header.length;
244 acpi_add_table(rsdt,madt);
248 printk_debug("ACPI: * SRAT\n");
249 srat = (acpi_srat_t *) current;
250 acpi_create_srat(srat);
251 current+=srat->header.length;
252 acpi_add_table(rsdt,srat);
255 printk_debug("ACPI: * SLIT\n");
256 slit = (acpi_slit_t *) current;
257 acpi_create_slit(slit);
258 current+=slit->header.length;
259 acpi_add_table(rsdt,slit);
262 printk_debug("ACPI: * SSDT\n");
263 ssdt = (acpi_header_t *)current;
265 acpi_create_ssdt_generator(ssdt, "DYNADATA");
266 current += ssdt->length;
267 acpi_add_table(rsdt, ssdt);
269 #if CONFIG_ACPI_SSDTX_NUM >= 1
271 //same htio, but different position? We may have to copy, change HCIN, and recalculate the checknum and add_table
273 for(i=1;i<sysconf.hc_possible_num;i++) { // 0: is hc sblink
274 if((sysconf.pci1234[i] & 1) != 1 ) continue;
277 c = (uint8_t) ('4' + i - 1);
280 c = (uint8_t) ('A' + i - 1 - 6);
282 printk_debug("ACPI: * SSDT for PCI%c Aka hcid = %d\n", c, sysconf.hcid[i]); //pci0 and pci1 are in dsdt
283 current = ( current + 0x07) & -0x08;
284 ssdtx = (acpi_header_t *)current;
285 switch(sysconf.hcid[i]) {
300 current += ((acpi_header_t *)p)->length;
301 memcpy((void *)ssdtx, (void *)p, ((acpi_header_t *)p)->length);
302 update_ssdtx((void *)ssdtx, i);
304 ssdtx->checksum = acpi_checksum((unsigned char *)ssdtx,ssdtx->length);
305 acpi_add_table(rsdt,ssdtx);
310 printk_debug("ACPI: * FACS\n");
311 facs = (acpi_facs_t *) current;
312 current += sizeof(acpi_facs_t);
313 acpi_create_facs(facs);
316 printk_debug("ACPI: * DSDT\n");
317 dsdt = (acpi_header_t *)current;
318 current += ((acpi_header_t *)AmlCode)->length;
319 memcpy((void *)dsdt,(void *)AmlCode, \
320 ((acpi_header_t *)AmlCode)->length);
321 printk_debug("ACPI: * DSDT @ %08x Length %x\n",dsdt,dsdt->length);
324 printk_debug("ACPI: * FADT\n");
325 fadt = (acpi_fadt_t *) current;
326 current += sizeof(acpi_fadt_t);
328 acpi_create_fadt(fadt,facs,dsdt);
329 acpi_add_table(rsdt,fadt);
331 #if DUMP_ACPI_TABLES == 1
332 printk_debug("rsdp\n");
333 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
335 printk_debug("rsdt\n");
336 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
338 printk_debug("madt\n");
339 dump_mem(madt, ((void *)madt) + madt->header.length);
341 printk_debug("srat\n");
342 dump_mem(srat, ((void *)srat) + srat->header.length);
344 printk_debug("slit\n");
345 dump_mem(slit, ((void *)slit) + slit->header.length);
347 printk_debug("ssdt\n");
348 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
350 printk_debug("fadt\n");
351 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
354 printk_info("ACPI: done.\n");