Index: acpi_tables.c
===================================================================
--- acpi_tables.c	(revision 0)
+++ acpi_tables.c	(revision 0)
@@ -0,0 +1,181 @@
+#include <console/console.h>
+#include <string.h>
+#include <arch/acpi.h>
+#include <arch/smp/mpspec.h>
+#include <device/device.h>
+#include <device/pci_ids.h>
+#include <device/pci_def.h>
+
+
+extern unsigned char AmlCode[];
+extern unsigned pm_base;
+
+unsigned long acpi_fill_mcfg(unsigned long current)
+{
+        /* Not Implemented */
+	return current;
+}
+
+unsigned long acpi_fill_madt(unsigned long current)
+{
+	unsigned long apic_addr;
+	device_t dev;
+
+	/* create all subtables for processors */
+	current = acpi_create_madt_lapics(current);
+
+	dev = dev_find_slot(bus_mcp55[0], PCI_DEVFN(sbdn+0x1,0));
+	if (dev) {
+		apic_addr = pci_read_config32(dev, PCI_BASE_ADDRESS_1) & ~0xf;
+		current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2,
+						apic_addr, 0);
+	}
+/* check the following TODO
+	dev = dev_find_slot(0x18, PCI_DEVFN(0x0,1)); //TODO: verify again, why you used 0x18 and if this is nessecary.
+	if (dev) {
+		apic_addr = pci_read_config32(dev, PCI_BASE_ADDRESS_0) & ~0xf;
+		current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2,
+							apic_addr, 0);
+	}*/
+	
+
+	/* IRQ9 ACPI active low. */
+	current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
+		current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
+
+	/* IRQ0 -> APIC IRQ2. */
+	current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
+							current, 0, 0, 2, 0x0);
+
+
+	/* some stuff from older work done on acpi. TODO: check tables against orignal if this would be neccesary.	
+	current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 0, 2, 0x0); 
+	current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 9, 9, 0xd);
+	current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 14, 14, 0x5);
+	current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 15, 15, 0x5); */
+	
+	/* Create all subtables for processors. */
+	current = acpi_create_madt_lapic_nmis(current,
+		MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
+}
+
+
+unsigned long acpi_fill_ssdt_generator(unsigned long current, char *oem_table_id) {
+	k8acpi_write_vars();
+//	amd_model_fxx_generate_powernow(pm_base + 8, 6, 1); //TODO: difference to next line!? (cpu-id in ssdt.asl ???)
+	amd_model_fxx_generate_powernow(0, 0, 0);
+	return (unsigned long) (acpigen_get_current());
+}
+
+
+unsigned long write_acpi_tables(unsigned long start)
+{
+	unsigned long current;
+	acpi_rsdp_t *rsdp;
+	acpi_srat_t *srat;
+	acpi_rsdt_t *rsdt;
+	acpi_mcfg_t *mcfg;
+	acpi_hpet_t *hpet;
+	acpi_madt_t *madt;
+	acpi_fadt_t *fadt;
+	acpi_facs_t *facs;
+	acpi_slit_t *slit;
+	acpi_header_t *dsdt;
+	acpi_header_t *ssdt;
+	
+	/* Align ACPI tables to 16 byte. */
+	start = (start + 0x0f) & -0x10;
+	current = start;
+
+	printk_info("ACPI: Writing ACPI tables at %lx...\n", start);
+
+	/* We need at least an RSDP and an RSDT table. */
+	rsdp = (acpi_rsdp_t *) current;
+	current += sizeof(acpi_rsdp_t);
+	rsdt = (acpi_rsdt_t *) current;
+	current += sizeof(acpi_rsdt_t);
+
+	/* Clear all table memory. */
+	memset((void *) start, 0, current - start);
+
+	acpi_write_rsdp(rsdp, rsdt);
+	acpi_write_rsdt(rsdt);
+
+	/* We explicitly add these tables later on: */
+	printk_debug("ACPI:     * FACS\n");
+
+	 /* we should align FACS to 64B as per ACPI specs */
+	current = ALIGN(current, 64);
+
+	facs = (acpi_facs_t *) current;
+	current += sizeof(acpi_facs_t);
+	acpi_create_facs(facs);
+
+	dsdt = (acpi_header_t *) current;
+	current += ((acpi_header_t *) AmlCode)->length;
+	memcpy((void *) dsdt, (void *) AmlCode,
+	       ((acpi_header_t *) AmlCode)->length);
+	dsdt->checksum = 0;	/* Don't trust iasl to get this right. */ 
+	/* looks like a brutal hack,
+	couldn't that be done a little more friendly? */
+
+	dsdt->checksum = acpi_checksum(dsdt, dsdt->length);
+	printk_debug("ACPI:     * DSDT @ %08x Length %x\n", dsdt,
+		     dsdt->length);
+	printk_debug("ACPI:     * FADT\n");
+
+	fadt = (acpi_fadt_t *) current;
+	current += sizeof(acpi_fadt_t);
+
+	acpi_create_fadt(fadt, facs, dsdt);
+	acpi_add_table(rsdt, fadt);
+	//TODO: checksum of fadt is incorrect - check why
+		
+        /* HPET */
+	printk_debug("ACPI:    * HPET\n");
+        hpet = (acpi_hpet_t *) current;
+        current += sizeof(acpi_hpet_t);
+        acpi_create_hpet(hpet);
+        acpi_add_table(rsdt, hpet);
+	//TODO: hpet is missing _CR symbol - check why (maybe because of original dsdt.asl)
+
+	/* If we want to use HPET timers Linux wants it in MADT. */
+	printk_debug("ACPI:    * MADT\n");
+	madt = (acpi_madt_t *) current;
+	acpi_create_madt(madt);
+	current += madt->header.length;
+	acpi_add_table(rsdt, madt);
+	
+	/* MCFG */
+	printk_debug("ACPI:    * MCFG\n");
+	mcfg = (acpi_mcfg_t *) current;
+	acpi_create_mcfg(mcfg);
+	current += mcfg->header.length;
+	acpi_add_table(rsdt, mcfg);
+	
+	/* SRAT */
+	printk_debug("ACPI:    * SRAT\n");
+	srat = (acpi_srat_t *) current;
+	acpi_create_srat(srat);
+	current += srat->header.length;
+	acpi_add_table(rsdt, srat);
+	
+        /* SLIT */
+        printk_debug("ACPI:    * SLIT\n");
+        slit = (acpi_slit_t *) current;
+        acpi_create_slit(slit);
+        current+=slit->header.length;
+        acpi_add_table(rsdt,slit);
+	
+	/* SSDT */	
+	printk_debug("ACPI:    * SSDT\n");
+        ssdt = (acpi_header_t *)current;
+	
+	/* DYNADATA */ /* used by the PowerNow! generator */
+	acpi_create_ssdt_generator(ssdt, "DYNADATA");	
+	current += ssdt->length;
+        acpi_add_table(rsdt, ssdt);
+	
+	printk_info("ACPI: done.\n");
+	return current;
+}
