2 * Agami Aruma ACPI support
4 * Copyright 2005 Stefan Reinauer
7 * written by Stefan Reinauer <stepan@openbios.org>
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 <../../../northbridge/amd/amdk8/amdk8_acpi.h>
20 #define DUMP_ACPI_TABLES 0
22 #if DUMP_ACPI_TABLES == 1
23 static void dump_mem(unsigned start, unsigned end)
27 print_debug("dump_mem:");
28 for (i = start; i < end; i++) {
30 printk_debug("\n%08x:", i);
33 (unsigned char) *((unsigned char *) i));
39 #define HC_POSSIBLE_NUM 8
40 extern unsigned char AmlCode[];
41 #if ACPI_SSDTX_NUM >= 1
42 extern unsigned char AmlCode_ssdt2[];
43 extern unsigned char AmlCode_ssdt3[];
44 extern unsigned char AmlCode_ssdt4[];
45 //extern unsigned char AmlCode_ssdt5[];
46 //extern unsigned char AmlCode_ssdt6[];
47 //extern unsigned char AmlCode_ssdt7[];
48 //extern unsigned char AmlCode_ssdt8[];
51 #define IO_APIC_ADDR 0xfec00000UL
53 extern unsigned char bus_isa;
54 extern unsigned char bus_8111_0;
55 extern unsigned char bus_8111_1;
56 extern unsigned char bus_8131[7][3]; // another 6 8131
57 extern unsigned apicid_8111;
58 extern unsigned apicid_8131[7][2];
60 extern unsigned pci1234[];
61 extern unsigned hc_possible_num;
64 extern unsigned hcdn[];
65 extern unsigned sbdnx[7]; // for all 8131
67 unsigned long acpi_fill_mcfg(unsigned long current)
73 unsigned long acpi_fill_madt(unsigned long current)
75 unsigned int gsi_base = 0x18;
77 /* create all subtables for processors */
78 current = acpi_create_madt_lapics(current);
80 /* Write 8111 IOAPIC */
81 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
82 apicid_8111, IO_APIC_ADDR, 0);
84 /* Write all 8131/8132 IOAPICs */
88 dev = dev_find_slot(bus_8131[0][0], PCI_DEVFN(sbdnx[0], 1));
91 res = find_resource(dev, PCI_BASE_ADDRESS_0);
93 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
94 apicid_8131[0][0], res->base, gsi_base);
99 dev = dev_find_slot(bus_8131[0][0], PCI_DEVFN(sbdnx[0] + 1, 1));
101 res = find_resource(dev, PCI_BASE_ADDRESS_0);
103 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
104 apicid_8131[0][1], res->base, gsi_base);
111 for (i = 1; i < hc_possible_num; i++)
115 struct resource *res;
117 if ((pci1234[i] & 1) != 1)
121 dev = dev_find_slot(bus_8131[j][0], PCI_DEVFN(sbdnx[j], 1));
124 res = find_resource(dev, PCI_BASE_ADDRESS_0);
126 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
127 apicid_8131[j][0], res->base, gsi_base);
133 dev_find_slot(bus_8131[j][0],
134 PCI_DEVFN(sbdnx[j] + 1, 1));
137 res = find_resource(dev, PCI_BASE_ADDRESS_0);
139 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
140 apicid_8131[j][1], res->base, gsi_base);
146 dev_find_slot(bus_8131[j + 1][0],
147 PCI_DEVFN(sbdnx[j + 1], 1));
151 res = find_resource(dev, PCI_BASE_ADDRESS_0);
153 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
154 apicid_8131[j + 1][0], res->base, gsi_base);
159 dev = dev_find_slot(bus_8131[j + 1][0], PCI_DEVFN(sbdnx[j + 1] + 1, 1));
162 res = find_resource(dev, PCI_BASE_ADDRESS_0);
164 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
165 apicid_8131[j + 1][1], res->base, gsi_base);
174 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 0, 2, 5);
175 /* 0: mean bus 0--->ISA */
178 /* 5 mean: 0101 --> Edige-triggered, Active high */
181 /* create all subtables for processors */
182 current = acpi_create_madt_lapic_nmis(current, 5, 1);
183 /* 1: LINT1 connect to NMI */
189 unsigned long acpi_fill_ssdt_generator(unsigned long current, char *oem_table_id) {
191 return (unsigned long) (acpigen_get_current());
194 unsigned long write_acpi_tables(unsigned long start)
196 unsigned long current;
206 acpi_header_t *ssdtx;
208 unsigned char *AmlCode_ssdtx[HC_POSSIBLE_NUM];
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);
230 get_bus_conf(); // get sblk, pci1234, and sbdn
233 * We explicitly add these tables later on:
235 printk_debug("ACPI: * HPET\n");
236 hpet = (acpi_hpet_t *) current;
237 current += sizeof(acpi_hpet_t);
238 acpi_create_hpet(hpet);
239 acpi_add_table(rsdt, hpet);
241 /* If we want to use HPET Timers Linux wants an MADT */
242 printk_debug("ACPI: * MADT\n");
243 madt = (acpi_madt_t *) current;
244 acpi_create_madt(madt);
245 current += madt->header.length;
246 acpi_add_table(rsdt, madt);
249 printk_debug("ACPI: * SRAT\n");
250 srat = (acpi_srat_t *) current;
251 acpi_create_srat(srat);
252 current += srat->header.length;
253 acpi_add_table(rsdt, srat);
256 printk_debug("ACPI: * SSDT\n");
257 ssdt = (acpi_header_t *)current;
259 acpi_create_ssdt_generator(ssdt, "DYNADATA");
260 current += ssdt->length;
261 acpi_add_table(rsdt, ssdt);
263 #if ACPI_SSDTX_NUM >= 1
264 // we need to make ssdt2 match to PCI2 in pci2.asl,... pci1234[1]
265 AmlCode_ssdtx[1] = AmlCode_ssdt2; // if you have different HT IO card for the same ht slot, here need to check vendor id, to set coresponding SSDT
266 AmlCode_ssdtx[2] = AmlCode_ssdt3;
267 AmlCode_ssdtx[3] = AmlCode_ssdt4;
268 // AmlCode_ssdtx[4] = AmlCode_ssdt5;
269 // AmlCode_ssdtx[5] = AmlCode_ssdt6;
270 // AmlCode_ssdtx[6] = AmlCode_ssdt7;
271 // AmlCode_ssdtx[7] = AmlCode_ssdt8;
273 //same htio, but different possition? We may have to copy, change HCIN, and recalculate the checknum and add_table
275 for (i = 1; i < hc_possible_num; i++) { // 0: is hc sblink
276 if ((pci1234[i] & 1) != 1)
278 printk_debug("ACPI: * SSDT for PCI%d\n", i + 1); //pci0 and pci1 are in dsdt
279 ssdtx = (acpi_header_t *) current;
280 current += ((acpi_header_t *) AmlCode_ssdtx[i])->length;
281 memcpy((void *) ssdtx, (void *) AmlCode_ssdtx[i],
282 ((acpi_header_t *) AmlCode_ssdtx[i])->length);
283 acpi_add_table(rsdt, ssdtx);
289 printk_debug("ACPI: * FACS\n");
290 facs = (acpi_facs_t *) current;
291 current += sizeof(acpi_facs_t);
292 acpi_create_facs(facs);
295 printk_debug("ACPI: * DSDT\n");
296 dsdt = (acpi_header_t *) current;
297 current += ((acpi_header_t *) AmlCode)->length;
298 memcpy((void *) dsdt, (void *) AmlCode,
299 ((acpi_header_t *) AmlCode)->length);
300 printk_debug("ACPI: * DSDT @ %08x Length %x\n", dsdt,
304 printk_debug("ACPI: * FADT\n");
305 fadt = (acpi_fadt_t *) current;
306 current += sizeof(acpi_fadt_t);
308 acpi_create_fadt(fadt, facs, dsdt);
309 acpi_add_table(rsdt, fadt);
311 #if DUMP_ACPI_TABLES == 1
312 printk_debug("rsdp\n");
313 dump_mem(rsdp, ((void *) rsdp) + sizeof(acpi_rsdp_t));
315 printk_debug("rsdt\n");
316 dump_mem(rsdt, ((void *) rsdt) + sizeof(acpi_rsdt_t));
318 printk_debug("madt\n");
319 dump_mem(madt, ((void *) madt) + madt->header.length);
321 printk_debug("srat\n");
322 dump_mem(srat, ((void *) srat) + srat->header.length);
324 printk_debug("ssdt\n");
325 dump_mem(ssdt, ((void *) ssdt) + ssdt->length);
327 printk_debug("fadt\n");
328 dump_mem(fadt, ((void *) fadt) + fadt->header.length);
331 printk_info("ACPI: done.\n");