From a91fff499f7be8ff7fb7187d1641bbbc1ad6ec5c Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Mon, 12 May 2014 03:34:21 +0200
Subject: [PATCH 3/4] WIP kernel/acpi: Use ACPICA types in platform code.

---
 sys/platform/pc64/acpica/acpi_fadt.c    |  35 +---
 sys/platform/pc64/acpica/acpi_madt.c    | 311 +++++++++++++-------------------
 sys/platform/pc64/acpica/acpi_sdt.c     |  84 ++++-----
 sys/platform/pc64/acpica/acpi_sdt.h     |  57 ------
 sys/platform/pc64/acpica/acpi_sdt_var.h |   5 +-
 5 files changed, 172 insertions(+), 320 deletions(-)
 delete mode 100644 sys/platform/pc64/acpica/acpi_sdt.h

diff --git a/sys/platform/pc64/acpica/acpi_fadt.c b/sys/platform/pc64/acpica/acpi_fadt.c
index 7089381..e28b7a9 100644
--- a/sys/platform/pc64/acpica/acpi_fadt.c
+++ b/sys/platform/pc64/acpica/acpi_fadt.c
@@ -40,7 +40,6 @@
 #include <sys/systm.h>
 #include <sys/thread2.h>
 
-#include "acpi_sdt.h"
 #include "acpi_sdt_var.h"
 #include "acpi_sci_var.h"
 
@@ -50,22 +49,6 @@ do { \
 		kprintf("ACPI FADT: " fmt , ##arg); \
 } while (0)
 
-/* Fixed ACPI Description Table */
-struct acpi_fadt {
-	struct acpi_sdth	fadt_hdr;
-	uint32_t		fadt_fw_ctrl;
-	uint32_t		fadt_dsdt;
-	uint8_t			fadt_rsvd1;
-	uint8_t			fadt_pm_prof;
-	uint16_t		fadt_sci_int;
-	uint32_t		fadt_smi_cmd;
-	uint8_t			fadt_acpi_en;
-	uint8_t			fadt_acpi_dis;
-	uint8_t			fadt_s4bios;
-	uint8_t			fadt_pstate;
-	/* More ... */
-} __packed;
-
 struct acpi_sci_mode {
 	enum intr_trigger	sci_trig;
 	enum intr_polarity	sci_pola;
@@ -92,14 +75,14 @@ static const struct acpi_sci_mode acpi_sci_modes[] = {
 static void
 fadt_probe(void)
 {
-	struct acpi_fadt *fadt;
+	ACPI_TABLE_FADT *fadt;
 	vm_paddr_t fadt_paddr;
 	enum intr_trigger trig;
 	enum intr_polarity pola;
 	int enabled = 1;
 	char *env;
 
-	fadt_paddr = sdt_search(ACPI_FADT_SIG);
+	fadt_paddr = sdt_search(ACPI_SIG_FADT);
 	if (fadt_paddr == 0) {
 		kprintf("fadt_probe: can't locate FADT\n");
 		return;
@@ -111,14 +94,14 @@ fadt_probe(void)
 	/*
 	 * FADT in ACPI specification 1.0 - 5.0
 	 */
-	if (fadt->fadt_hdr.sdth_rev < 1 || fadt->fadt_hdr.sdth_rev > 5) {
+	if (fadt->Header.Revision < 1 || fadt->Header.Revision > 5) {
 		kprintf("fadt_probe: unknown FADT revision %d\n",
-			fadt->fadt_hdr.sdth_rev);
+			fadt->Header.Revision);
 	}
 
-	if (fadt->fadt_hdr.sdth_len < sizeof(*fadt)) {
-		kprintf("fadt_probe: invalid FADT length %u\n",
-			fadt->fadt_hdr.sdth_len);
+	if (fadt->Header.Length < sizeof(*fadt)) {
+		kprintf("fadt_probe: invalid FADT length %u (< %zd)\n",
+		    fadt->Header.Length, sizeof(*fadt));
 		goto back;
 	}
 
@@ -126,7 +109,7 @@ fadt_probe(void)
 	if (!enabled)
 		goto back;
 
-	acpi_sci_irq = fadt->fadt_sci_int;
+	acpi_sci_irq = fadt->SciInterrupt;
 
 	env = kgetenv("hw.acpi.sci.trigger");
 	if (env == NULL)
@@ -168,7 +151,7 @@ back:
 	} else {
 		FADT_VPRINTF("SCI is disabled\n");
 	}
-	sdt_sdth_unmap(&fadt->fadt_hdr);
+	sdt_sdth_unmap(&fadt->Header);
 }
 SYSINIT(fadt_probe, SI_BOOT2_PRESMP, SI_ORDER_SECOND, fadt_probe, 0);
 
diff --git a/sys/platform/pc64/acpica/acpi_madt.c b/sys/platform/pc64/acpica/acpi_madt.c
index d8f7249..7939006 100644
--- a/sys/platform/pc64/acpica/acpi_madt.c
+++ b/sys/platform/pc64/acpica/acpi_madt.c
@@ -42,7 +42,9 @@
 #include <machine_base/apic/ioapic.h>
 #include <machine_base/apic/apicvar.h>
 
-#include "acpi_sdt.h"
+#include <contrib/dev/acpica/source/include/acpi.h>
+#include <contrib/dev/acpica/source/include/actables.h>
+
 #include "acpi_sdt_var.h"
 #include "acpi_sci_var.h"
 
@@ -54,80 +56,16 @@ do { \
 		kprintf("ACPI MADT: " fmt , ##arg); \
 } while (0)
 
-/* Multiple APIC Description Table */
-struct acpi_madt {
-	struct acpi_sdth	madt_hdr;
-	uint32_t		madt_lapic_addr;
-	uint32_t		madt_flags;
-	uint8_t			madt_ents[1];
-} __packed;
-
-/* Common parts of MADT APIC structure */
-struct acpi_madt_ent {
-	uint8_t			me_type;	/* MADT_ENT_ */
-	uint8_t			me_len;
-} __packed;
-
-#define MADT_ENT_LAPIC		0
-#define MADT_ENT_IOAPIC		1
-#define MADT_ENT_INTSRC		2
-#define MADT_ENT_LAPIC_ADDR	5
-
-/* MADT Processor Local APIC */
-struct acpi_madt_lapic {
-	struct acpi_madt_ent	ml_hdr;
-	uint8_t			ml_cpu_id;
-	uint8_t			ml_apic_id;
-	uint32_t		ml_flags;	/* MADT_LAPIC_ */
-} __packed;
-
-#define MADT_LAPIC_ENABLED	0x1
-
-/* MADT I/O APIC */
-struct acpi_madt_ioapic {
-	struct acpi_madt_ent	mio_hdr;
-	uint8_t			mio_apic_id;
-	uint8_t			mio_reserved;
-	uint32_t		mio_addr;
-	uint32_t		mio_gsi_base;
-} __packed;
-
-/* MADT Interrupt Source Override */
-struct acpi_madt_intsrc {
-	struct acpi_madt_ent	mint_hdr;
-	uint8_t			mint_bus;	/* MADT_INT_BUS_ */
-	uint8_t			mint_src;
-	uint32_t		mint_gsi;
-	uint16_t		mint_flags;	/* MADT_INT_ */
-} __packed;
-
 #define MADT_INT_BUS_ISA	0
 
-#define MADT_INT_POLA_MASK	0x3
 #define MADT_INT_POLA_SHIFT	0
-#define MADT_INT_POLA_CONFORM	0
-#define MADT_INT_POLA_HIGH	1
-#define MADT_INT_POLA_RSVD	2
-#define MADT_INT_POLA_LOW	3
-#define MADT_INT_TRIG_MASK	0xc
 #define MADT_INT_TRIG_SHIFT	2
-#define MADT_INT_TRIG_CONFORM	0
-#define MADT_INT_TRIG_EDGE	1
-#define MADT_INT_TRIG_RSVD	2
-#define MADT_INT_TRIG_LEVEL	3
-
-/* MADT Local APIC Address Override */
-struct acpi_madt_lapic_addr {
-	struct acpi_madt_ent	mla_hdr;
-	uint16_t		mla_reserved;
-	uint64_t		mla_lapic_addr;
-} __packed;
 
 typedef int			(*madt_iter_t)(void *,
-				    const struct acpi_madt_ent *);
+				    const ACPI_SUBTABLE_HEADER *);
 
 static int			madt_check(vm_paddr_t);
-static int			madt_iterate_entries(struct acpi_madt *,
+static int			madt_iterate_entries(ACPI_TABLE_MADT *,
 				    madt_iter_t, void *);
 
 static vm_paddr_t		madt_lapic_pass1(void);
@@ -149,7 +87,7 @@ madt_probe(void)
 
 	KKASSERT(madt_phyaddr == 0);
 
-	madt_paddr = sdt_search(ACPI_MADT_SIG);
+	madt_paddr = sdt_search(ACPI_SIG_MADT);
 	if (madt_paddr == 0) {
 		kprintf("madt_probe: can't locate MADT\n");
 		return;
@@ -168,7 +106,7 @@ SYSINIT(madt_probe, SI_BOOT2_PRESMP, SI_ORDER_SECOND, madt_probe, 0);
 static int
 madt_check(vm_paddr_t madt_paddr)
 {
-	struct acpi_madt *madt;
+	ACPI_TABLE_MADT *madt;
 	int error = 0;
 
 	KKASSERT(madt_paddr != 0);
@@ -179,78 +117,75 @@ madt_check(vm_paddr_t madt_paddr)
 	/*
 	 * MADT in ACPI specification 1.0 - 5.0
 	 */
-	if (madt->madt_hdr.sdth_rev < 1 || madt->madt_hdr.sdth_rev > 3) {
+	if (madt->Header.Revision < 1 || madt->Header.Revision > 3) {
 		kprintf("madt_check: unknown MADT revision %d\n",
-			madt->madt_hdr.sdth_rev);
+			madt->Header.Revision);
 	}
 
-	if (madt->madt_hdr.sdth_len <
-	    sizeof(*madt) - sizeof(madt->madt_ents)) {
+	if (madt->Header.Length < sizeof(*madt)) {
 		kprintf("madt_check: invalid MADT length %u\n",
-			madt->madt_hdr.sdth_len);
+			madt->Header.Length);
 		error = EINVAL;
 		goto back;
 	}
 back:
-	sdt_sdth_unmap(&madt->madt_hdr);
+	sdt_sdth_unmap(&madt->Header);
 	return error;
 }
 
 static int
-madt_iterate_entries(struct acpi_madt *madt, madt_iter_t func, void *arg)
+madt_iterate_entries(ACPI_TABLE_MADT *madt, madt_iter_t func, void *arg)
 {
 	int size, cur, error;
+	const ACPI_SUBTABLE_HEADER *ent;
 
-	size = madt->madt_hdr.sdth_len -
-	       (sizeof(*madt) - sizeof(madt->madt_ents));
+	size = madt->Header.Length - sizeof(*madt);
 	cur = 0;
 	error = 0;
+	ent = (const ACPI_SUBTABLE_HEADER *)((char *)madt + madt->Header.Length);
 
-	while (size - cur > sizeof(struct acpi_madt_ent)) {
-		const struct acpi_madt_ent *ent;
-
-		ent = (const struct acpi_madt_ent *)&madt->madt_ents[cur];
-		if (ent->me_len < sizeof(*ent)) {
+	while (size - cur > sizeof(ACPI_SUBTABLE_HEADER)) {
+		if (ent->Length < sizeof(*ent)) {
 			kprintf("madt_iterate_entries: invalid MADT "
-				"entry len %d\n", ent->me_len);
+				"entry len %d\n", ent->Length);
 			error = EINVAL;
 			break;
 		}
-		if (ent->me_len > (size - cur)) {
+		if (ent->Length > (size - cur)) {
 			kprintf("madt_iterate_entries: invalid MADT "
-				"entry len %d, > table length\n", ent->me_len);
+				"entry len %d, > table length\n", ent->Length);
 			error = EINVAL;
 			break;
 		}
 
-		cur += ent->me_len;
+		cur += ent->Length;
 
 		/*
 		 * Only Local APIC, I/O APIC and Interrupt Source Override
 		 * are defined in ACPI specification 1.0 - 5.0
 		 */
-		switch (ent->me_type) {
-		case MADT_ENT_LAPIC:
-			if (ent->me_len < sizeof(struct acpi_madt_lapic)) {
+		switch (ent->Type) {
+		case ACPI_MADT_TYPE_LOCAL_APIC:
+			if (ent->Length < sizeof(ACPI_MADT_LOCAL_APIC)) {
 				kprintf("madt_iterate_entries: invalid MADT "
-					"lapic entry len %d\n", ent->me_len);
+					"lapic entry len %d\n", ent->Length);
 				error = EINVAL;
 			}
 			break;
 
-		case MADT_ENT_IOAPIC:
-			if (ent->me_len < sizeof(struct acpi_madt_ioapic)) {
+		case ACPI_MADT_TYPE_IO_APIC:
+			if (ent->Length < sizeof(ACPI_MADT_IO_APIC)) {
 				kprintf("madt_iterate_entries: invalid MADT "
-					"ioapic entry len %d\n", ent->me_len);
+					"ioapic entry len %d\n", ent->Length);
 				error = EINVAL;
 			}
 			break;
 
-		case MADT_ENT_INTSRC:
-			if (ent->me_len < sizeof(struct acpi_madt_intsrc)) {
+		case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
+			if (ent->Length < sizeof(ACPI_MADT_INTERRUPT_OVERRIDE)) {
 				kprintf("madt_iterate_entries: invalid MADT "
 					"intsrc entry len %d\n",
-					ent->me_len);
+					ent->Length);
 				error = EINVAL;
 			}
 			break;
@@ -261,33 +196,35 @@ madt_iterate_entries(struct acpi_madt *madt, madt_iter_t func, void *arg)
 		error = func(arg, ent);
 		if (error)
 			break;
+
+		ent = ACPI_ADD_PTR(ACPI_SUBTABLE_HEADER, ent, ent->Length);
 	}
 	return error;
 }
 
 static int
-madt_lapic_pass1_callback(void *xarg, const struct acpi_madt_ent *ent)
+madt_lapic_pass1_callback(void *xarg, const ACPI_SUBTABLE_HEADER *ent)
 {
-	const struct acpi_madt_lapic_addr *lapic_addr_ent;
+	const ACPI_MADT_LOCAL_APIC_OVERRIDE *lapic_addr_ent;
 	uint64_t *addr64 = xarg;
 
-	if (ent->me_type != MADT_ENT_LAPIC_ADDR)
+	if (ent->Type != ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE)
 		return 0;
-	if (ent->me_len < sizeof(*lapic_addr_ent)) {
+	if (ent->Length < sizeof(*lapic_addr_ent)) {
 		kprintf("madt_lapic_pass1: "
 			"invalid LAPIC address override length\n");
 		return 0;
 	}
-	lapic_addr_ent = (const struct acpi_madt_lapic_addr *)ent;
+	lapic_addr_ent = (const ACPI_MADT_LOCAL_APIC_OVERRIDE *)ent;
 
-	*addr64 = lapic_addr_ent->mla_lapic_addr;
+	*addr64 = lapic_addr_ent->Address;
 	return 0;
 }
 
 static vm_paddr_t
 madt_lapic_pass1(void)
 {
-	struct acpi_madt *madt;
+	ACPI_TABLE_MADT *madt;
 	vm_paddr_t lapic_addr;
 	uint64_t lapic_addr64;
 	int error;
@@ -298,8 +235,8 @@ madt_lapic_pass1(void)
 	KKASSERT(madt != NULL);
 
 	MADT_VPRINTF("LAPIC address 0x%x, flags %#x\n",
-		     madt->madt_lapic_addr, madt->madt_flags);
-	lapic_addr = madt->madt_lapic_addr;
+		     madt->Address, madt->Flags);
+	lapic_addr = madt->Address;
 
 	lapic_addr64 = 0;
 	error = madt_iterate_entries(madt, madt_lapic_pass1_callback,
@@ -313,7 +250,7 @@ madt_lapic_pass1(void)
 		lapic_addr = lapic_addr64;
 	}
 
-	sdt_sdth_unmap(&madt->madt_hdr);
+	sdt_sdth_unmap(&madt->Header);
 
 	return lapic_addr;
 }
@@ -325,23 +262,23 @@ struct madt_lapic_pass2_cbarg {
 };
 
 static int
-madt_lapic_pass2_callback(void *xarg, const struct acpi_madt_ent *ent)
+madt_lapic_pass2_callback(void *xarg, const ACPI_SUBTABLE_HEADER *ent)
 {
-	const struct acpi_madt_lapic *lapic_ent;
+	const ACPI_MADT_LOCAL_APIC *lapic_ent;
 	struct madt_lapic_pass2_cbarg *arg = xarg;
 
-	if (ent->me_type != MADT_ENT_LAPIC)
+	if (ent->Type != ACPI_MADT_TYPE_LOCAL_APIC)
 		return 0;
 
-	lapic_ent = (const struct acpi_madt_lapic *)ent;
-	if (lapic_ent->ml_flags & MADT_LAPIC_ENABLED) {
+	lapic_ent = (const ACPI_MADT_LOCAL_APIC *)ent;
+	if (lapic_ent->LapicFlags & ACPI_MADT_ENABLED) {
 		MADT_VPRINTF("cpu id %d, apic id %d\n",
-			     lapic_ent->ml_cpu_id, lapic_ent->ml_apic_id);
-		if (lapic_ent->ml_apic_id == arg->bsp_apic_id) {
-			lapic_set_cpuid(0, lapic_ent->ml_apic_id);
+			     lapic_ent->ProcessorId, lapic_ent->Id);
+		if (lapic_ent->Id == arg->bsp_apic_id) {
+			lapic_set_cpuid(0, lapic_ent->Id);
 			arg->bsp_found = 1;
 		} else {
-			lapic_set_cpuid(arg->cpu, lapic_ent->ml_apic_id);
+			lapic_set_cpuid(arg->cpu, lapic_ent->Id);
 			arg->cpu++;
 		}
 	}
@@ -351,7 +288,7 @@ madt_lapic_pass2_callback(void *xarg, const struct acpi_madt_ent *ent)
 static int
 madt_lapic_pass2(int bsp_apic_id)
 {
-	struct acpi_madt *madt;
+	ACPI_TABLE_MADT *madt;
 	struct madt_lapic_pass2_cbarg arg;
 	int error;
 
@@ -373,7 +310,7 @@ madt_lapic_pass2(int bsp_apic_id)
 	KKASSERT(arg.bsp_found);
 	naps = arg.cpu - 1; /* exclude BSP */
 
-	sdt_sdth_unmap(&madt->madt_hdr);
+	sdt_sdth_unmap(&madt->Header);
 
 	return 0;
 }
@@ -384,35 +321,35 @@ struct madt_lapic_probe_cbarg {
 };
 
 static int
-madt_lapic_probe_callback(void *xarg, const struct acpi_madt_ent *ent)
+madt_lapic_probe_callback(void *xarg, const ACPI_SUBTABLE_HEADER *ent)
 {
 	struct madt_lapic_probe_cbarg *arg = xarg;
 
-	if (ent->me_type == MADT_ENT_LAPIC) {
-		const struct acpi_madt_lapic *lapic_ent;
+	if (ent->Type == ACPI_MADT_TYPE_LOCAL_APIC) {
+		const ACPI_MADT_LOCAL_APIC *lapic_ent;
 
-		lapic_ent = (const struct acpi_madt_lapic *)ent;
-		if (lapic_ent->ml_flags & MADT_LAPIC_ENABLED) {
+		lapic_ent = (const ACPI_MADT_LOCAL_APIC *)ent;
+		if (lapic_ent->LapicFlags & ACPI_MADT_ENABLED) {
 			arg->cpu_count++;
-			if (lapic_ent->ml_apic_id == APICID_MAX) {
+			if (lapic_ent->Id == APICID_MAX) {
 				kprintf("madt_lapic_probe: "
 				    "invalid LAPIC apic id %d\n",
-				    lapic_ent->ml_apic_id);
+				    lapic_ent->Id);
 				return EINVAL;
 			}
 		}
-	} else if (ent->me_type == MADT_ENT_LAPIC_ADDR) {
-		const struct acpi_madt_lapic_addr *lapic_addr_ent;
+	} else if (ent->Type == ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE) {
+		const ACPI_MADT_LOCAL_APIC_OVERRIDE *lapic_addr_ent;
 
-		if (ent->me_len < sizeof(*lapic_addr_ent)) {
+		if (ent->Length < sizeof(*lapic_addr_ent)) {
 			kprintf("madt_lapic_probe: "
 				"invalid LAPIC address override length\n");
 			return 0;
 		}
-		lapic_addr_ent = (const struct acpi_madt_lapic_addr *)ent;
+		lapic_addr_ent = (const ACPI_MADT_LOCAL_APIC_OVERRIDE *)ent;
 
-		if (lapic_addr_ent->mla_lapic_addr != 0)
-			arg->lapic_addr = lapic_addr_ent->mla_lapic_addr;
+		if (lapic_addr_ent->Address != 0)
+			arg->lapic_addr = lapic_addr_ent->Address;
 	}
 	return 0;
 }
@@ -421,7 +358,7 @@ static int
 madt_lapic_probe(struct lapic_enumerator *e)
 {
 	struct madt_lapic_probe_cbarg arg;
-	struct acpi_madt *madt;
+	ACPI_TABLE_MADT *madt;
 	int error;
 
 	if (madt_phyaddr == 0)
@@ -431,7 +368,7 @@ madt_lapic_probe(struct lapic_enumerator *e)
 	KKASSERT(madt != NULL);
 
 	bzero(&arg, sizeof(arg));
-	arg.lapic_addr = madt->madt_lapic_addr;
+	arg.lapic_addr = madt->Address;
 
 	error = madt_iterate_entries(madt, madt_lapic_probe_callback, &arg);
 	if (!error) {
@@ -445,7 +382,7 @@ madt_lapic_probe(struct lapic_enumerator *e)
 		}
 	}
 
-	sdt_sdth_unmap(&madt->madt_hdr);
+	sdt_sdth_unmap(&madt->Header);
 	return error;
 }
 
@@ -506,64 +443,64 @@ struct madt_ioapic_probe_cbarg {
 };
 
 static int
-madt_ioapic_probe_callback(void *xarg, const struct acpi_madt_ent *ent)
+madt_ioapic_probe_callback(void *xarg, const ACPI_SUBTABLE_HEADER *ent)
 {
 	struct madt_ioapic_probe_cbarg *arg = xarg;
 
-	if (ent->me_type == MADT_ENT_INTSRC) {
-		const struct acpi_madt_intsrc *intsrc_ent;
+	if (ent->Type == ACPI_MADT_TYPE_INTERRUPT_OVERRIDE) {
+		const ACPI_MADT_INTERRUPT_OVERRIDE *intsrc_ent;
 		int trig, pola;
 
-		intsrc_ent = (const struct acpi_madt_intsrc *)ent;
+		intsrc_ent = (const ACPI_MADT_INTERRUPT_OVERRIDE *)ent;
 
-		if (intsrc_ent->mint_src >= ISA_IRQ_CNT) {
+		if (intsrc_ent->SourceIrq >= ISA_IRQ_CNT) {
 			kprintf("madt_ioapic_probe: invalid intsrc irq (%d)\n",
-				intsrc_ent->mint_src);
+				intsrc_ent->SourceIrq);
 			return EINVAL;
 		}
 
-		if (intsrc_ent->mint_bus != MADT_INT_BUS_ISA) {
+		if (intsrc_ent->Bus != MADT_INT_BUS_ISA) {
 			kprintf("ACPI MADT: warning intsrc irq %d "
 				"bus is not ISA (%d)\n",
-				intsrc_ent->mint_src, intsrc_ent->mint_bus);
+				intsrc_ent->SourceIrq, intsrc_ent->Bus);
 		}
 
-		trig = (intsrc_ent->mint_flags & MADT_INT_TRIG_MASK) >>
+		trig = (intsrc_ent->IntiFlags & ACPI_MADT_TRIGGER_MASK) >>
 		       MADT_INT_TRIG_SHIFT;
-		if (trig == MADT_INT_TRIG_RSVD) {
+		if (trig == ACPI_MADT_TRIGGER_RESERVED) {
 			kprintf("ACPI MADT: warning invalid intsrc irq %d "
-				"trig, reserved\n", intsrc_ent->mint_src);
-		} else if (trig == MADT_INT_TRIG_LEVEL) {
+				"trig, reserved\n", intsrc_ent->SourceIrq);
+		} else if (trig == ACPI_MADT_TRIGGER_LEVEL) {
 			MADT_VPRINTF("warning invalid intsrc irq %d "
-			    "trig, level\n", intsrc_ent->mint_src);
+			    "trig, level\n", intsrc_ent->SourceIrq);
 		}
 
-		pola = (intsrc_ent->mint_flags & MADT_INT_POLA_MASK) >>
+		pola = (intsrc_ent->IntiFlags & ACPI_MADT_POLARITY_MASK) >>
 		       MADT_INT_POLA_SHIFT;
-		if (pola == MADT_INT_POLA_RSVD) {
+		if (pola == ACPI_MADT_POLARITY_RESERVED) {
 			kprintf("ACPI MADT: warning invalid intsrc irq %d "
-				"pola, reserved\n", intsrc_ent->mint_src);
-		} else if (pola == MADT_INT_POLA_LOW) {
+				"pola, reserved\n", intsrc_ent->SourceIrq);
+		} else if (pola == ACPI_MADT_POLARITY_ACTIVE_LOW) {
 			MADT_VPRINTF("warning invalid intsrc irq %d "
-			    "pola, low\n", intsrc_ent->mint_src);
+			    "pola, low\n", intsrc_ent->SourceIrq);
 		}
-	} else if (ent->me_type == MADT_ENT_IOAPIC) {
-		const struct acpi_madt_ioapic *ioapic_ent;
+	} else if (ent->Type == ACPI_MADT_TYPE_IO_APIC) {
+		const ACPI_MADT_IO_APIC *ioapic_ent;
 
-		ioapic_ent = (const struct acpi_madt_ioapic *)ent;
-		if (ioapic_ent->mio_addr == 0) {
+		ioapic_ent = (const ACPI_MADT_IO_APIC *)ent;
+		if (ioapic_ent->Address == 0) {
 			kprintf("madt_ioapic_probe: zero IOAPIC address\n");
 			return EINVAL;
 		}
-		if (ioapic_ent->mio_apic_id == APICID_MAX) {
+		if (ioapic_ent->Id == APICID_MAX) {
 			kprintf("madt_ioapic_probe: "
 			    "invalid IOAPIC apic id %d\n",
-			    ioapic_ent->mio_apic_id);
+			    ioapic_ent->Id);
 			return EINVAL;
 		}
 
 		arg->ioapic_cnt++;
-		if (ioapic_ent->mio_gsi_base == 0)
+		if (ioapic_ent->GlobalIrqBase == 0)
 			arg->gsi_base0 = 1;
 	}
 	return 0;
@@ -573,7 +510,7 @@ static int
 madt_ioapic_probe(struct ioapic_enumerator *e)
 {
 	struct madt_ioapic_probe_cbarg arg;
-	struct acpi_madt *madt;
+	ACPI_TABLE_MADT *madt;
 	int error;
 
 	if (madt_phyaddr == 0)
@@ -596,47 +533,47 @@ madt_ioapic_probe(struct ioapic_enumerator *e)
 		}
 	}
 
-	sdt_sdth_unmap(&madt->madt_hdr);
+	sdt_sdth_unmap(&madt->Header);
 	return error;
 }
 
 static int
-madt_ioapic_enum_callback(void *xarg, const struct acpi_madt_ent *ent)
+madt_ioapic_enum_callback(void *xarg, const ACPI_SUBTABLE_HEADER *ent)
 {
-	if (ent->me_type == MADT_ENT_INTSRC) {
-		const struct acpi_madt_intsrc *intsrc_ent;
+	if (ent->Type == ACPI_MADT_TYPE_INTERRUPT_OVERRIDE) {
+		const ACPI_MADT_INTERRUPT_OVERRIDE *intsrc_ent;
 		enum intr_trigger trig;
 		enum intr_polarity pola;
 		int ent_trig, ent_pola;
 
-		intsrc_ent = (const struct acpi_madt_intsrc *)ent;
+		intsrc_ent = (const ACPI_MADT_INTERRUPT_OVERRIDE *)ent;
 
-		KKASSERT(intsrc_ent->mint_src < ISA_IRQ_CNT);
-		if (intsrc_ent->mint_bus != MADT_INT_BUS_ISA)
+		KKASSERT(intsrc_ent->SourceIrq < ISA_IRQ_CNT);
+		if (intsrc_ent->Bus != MADT_INT_BUS_ISA)
 			return 0;
 
-		ent_trig = (intsrc_ent->mint_flags & MADT_INT_TRIG_MASK) >>
+		ent_trig = (intsrc_ent->IntiFlags & ACPI_MADT_TRIGGER_MASK) >>
 		    MADT_INT_TRIG_SHIFT;
-		if (ent_trig == MADT_INT_TRIG_RSVD)
+		if (ent_trig == ACPI_MADT_TRIGGER_RESERVED)
 			return 0;
-		else if (ent_trig == MADT_INT_TRIG_LEVEL)
+		else if (ent_trig == ACPI_MADT_TRIGGER_LEVEL)
 			trig = INTR_TRIGGER_LEVEL;
 		else
 			trig = INTR_TRIGGER_EDGE;
 
-		ent_pola = (intsrc_ent->mint_flags & MADT_INT_POLA_MASK) >>
+		ent_pola = (intsrc_ent->IntiFlags & ACPI_MADT_POLARITY_MASK) >>
 		    MADT_INT_POLA_SHIFT;
-		if (ent_pola == MADT_INT_POLA_RSVD)
+		if (ent_pola == ACPI_MADT_POLARITY_RESERVED)
 			return 0;
-		else if (ent_pola == MADT_INT_POLA_LOW)
+		else if (ent_pola == ACPI_MADT_POLARITY_ACTIVE_LOW)
 			pola = INTR_POLARITY_LOW;
 		else
 			pola = INTR_POLARITY_HIGH;
 
-		if (intsrc_ent->mint_src == acpi_sci_irqno()) {
+		if (intsrc_ent->SourceIrq == acpi_sci_irqno()) {
 			acpi_sci_setmode1(trig, pola);
 			MADT_VPRINTF("SCI irq %d, first test %s/%s\n",
-			    intsrc_ent->mint_src,
+			    intsrc_ent->SourceIrq,
 			    intr_str_trigger(trig), intr_str_polarity(pola));
 		}
 
@@ -644,7 +581,7 @@ madt_ioapic_enum_callback(void *xarg, const struct acpi_madt_ent *ent)
 		 * We ignore the polarity and trigger changes, since
 		 * most of them are wrong or useless at best.
 		 */
-		if (intsrc_ent->mint_src == intsrc_ent->mint_gsi) {
+		if (intsrc_ent->SourceIrq == intsrc_ent->GlobalIrq) {
 			/* Nothing changed */
 			return 0;
 		}
@@ -652,27 +589,27 @@ madt_ioapic_enum_callback(void *xarg, const struct acpi_madt_ent *ent)
 		pola = INTR_POLARITY_HIGH;
 
 		MADT_VPRINTF("INTSRC irq %d -> gsi %u %s/%s\n",
-			     intsrc_ent->mint_src, intsrc_ent->mint_gsi,
+			     intsrc_ent->SourceIrq, intsrc_ent->GlobalIrq,
 			     intr_str_trigger(trig), intr_str_polarity(pola));
-		ioapic_intsrc(intsrc_ent->mint_src, intsrc_ent->mint_gsi,
+		ioapic_intsrc(intsrc_ent->SourceIrq, intsrc_ent->GlobalIrq,
 			      trig, pola);
-	} else if (ent->me_type == MADT_ENT_IOAPIC) {
-		const struct acpi_madt_ioapic *ioapic_ent;
+	} else if (ent->Type == ACPI_MADT_TYPE_IO_APIC) {
+		const ACPI_MADT_IO_APIC *ioapic_ent;
 		uint32_t ver;
 		void *addr;
 		int npin;
 
-		ioapic_ent = (const struct acpi_madt_ioapic *)ent;
+		ioapic_ent = (const ACPI_MADT_IO_APIC *)ent;
 		MADT_VPRINTF("IOAPIC addr 0x%08x, apic id %d, gsi base %u\n",
-			     ioapic_ent->mio_addr, ioapic_ent->mio_apic_id,
-			     ioapic_ent->mio_gsi_base);
+			     ioapic_ent->Address, ioapic_ent->Id,
+			     ioapic_ent->GlobalIrqBase);
 
-		addr = ioapic_map(ioapic_ent->mio_addr);
+		addr = ioapic_map(ioapic_ent->Address);
 
 		ver = ioapic_read(addr, IOAPIC_VER);
 		npin = ((ver & IOART_VER_MAXREDIR) >> MAXREDIRSHIFT) + 1;
 
-		ioapic_add(addr, ioapic_ent->mio_gsi_base, npin);
+		ioapic_add(addr, ioapic_ent->GlobalIrqBase, npin);
 	}
 	return 0;
 }
@@ -680,7 +617,7 @@ madt_ioapic_enum_callback(void *xarg, const struct acpi_madt_ent *ent)
 static void
 madt_ioapic_enumerate(struct ioapic_enumerator *e)
 {
-	struct acpi_madt *madt;
+	ACPI_TABLE_MADT *madt;
 	int error;
 
 	KKASSERT(madt_phyaddr != 0);
@@ -692,7 +629,7 @@ madt_ioapic_enumerate(struct ioapic_enumerator *e)
 	if (error)
 		panic("madt_ioapic_enumerate failed");
 
-	sdt_sdth_unmap(&madt->madt_hdr);
+	sdt_sdth_unmap(&madt->Header);
 }
 
 static struct ioapic_enumerator	madt_ioapic_enumerator = {
diff --git a/sys/platform/pc64/acpica/acpi_sdt.c b/sys/platform/pc64/acpica/acpi_sdt.c
index e8d2252..a24f057 100644
--- a/sys/platform/pc64/acpica/acpi_sdt.c
+++ b/sys/platform/pc64/acpica/acpi_sdt.c
@@ -38,7 +38,6 @@
 
 #include <machine/pmap.h>
 
-#include "acpi_sdt.h"
 #include "acpi_sdt_var.h"
 
 #define SDT_VPRINTF(fmt, arg...) \
@@ -54,7 +53,6 @@ do { \
 #define ACPI_RSDP_ALIGN		16
 
 #define ACPI_RSDP_SIGLEN	8
-#define ACPI_RSDP_SIG		"RSD PTR "
 
 /* Root System Description Pointer */
 struct acpi_rsdp {
@@ -69,18 +67,6 @@ struct acpi_rsdp {
 	uint8_t			rsdp_rsvd[3];
 } __packed;
 
-/* Extended System Description Table */
-struct acpi_xsdt {
-	struct acpi_sdth	xsdt_hdr;
-	uint64_t		xsdt_ents[1];
-} __packed;
-
-/* Root System Description Table */
-struct acpi_rsdt {
-	struct acpi_sdth	rsdt_hdr;
-	uint32_t		rsdt_ents[1];
-} __packed;
-
 typedef	vm_paddr_t		(*sdt_search_t)(vm_paddr_t, const uint8_t *);
 
 static const struct acpi_rsdp	*sdt_rsdp_search(const uint8_t *, int);
@@ -150,7 +136,7 @@ sdt_rsdp_search(const uint8_t *target, int size)
 
 	for (i = 0; i < size - sizeof(*rsdp); i += ACPI_RSDP_ALIGN) {
 		rsdp = (const struct acpi_rsdp *)&target[i];
-		if (memcmp(rsdp->rsdp_sig, ACPI_RSDP_SIG,
+		if (memcmp(rsdp->rsdp_sig, ACPI_SIG_RSDP,
 			   ACPI_RSDP_SIGLEN) == 0)
 			return rsdp;
 	}
@@ -160,11 +146,11 @@ sdt_rsdp_search(const uint8_t *target, int size)
 void *
 sdt_sdth_map(vm_paddr_t paddr)
 {
-	struct acpi_sdth *sdth;
+	ACPI_TABLE_HEADER *sdth;
 	vm_size_t mapsz;
 
 	sdth = pmap_mapdev(paddr, sizeof(*sdth));
-	mapsz = sdth->sdth_len;
+	mapsz = sdth->Length;
 	pmap_unmapdev((vm_offset_t)sdth, sizeof(*sdth));
 
 	if (mapsz < sizeof(*sdth))
@@ -174,15 +160,15 @@ sdt_sdth_map(vm_paddr_t paddr)
 }
 
 void
-sdt_sdth_unmap(struct acpi_sdth *sdth)
+sdt_sdth_unmap(ACPI_TABLE_HEADER *sdth)
 {
-	pmap_unmapdev((vm_offset_t)sdth, sdth->sdth_len);
+	pmap_unmapdev((vm_offset_t)sdth, sdth->Length);
 }
 
 static vm_paddr_t
 sdt_search_xsdt(vm_paddr_t xsdt_paddr, const uint8_t *sig)
 {
-	struct acpi_xsdt *xsdt;
+	ACPI_TABLE_XSDT *xsdt;
 	vm_paddr_t sdt_paddr = 0;
 	int i, nent;
 
@@ -197,53 +183,53 @@ sdt_search_xsdt(vm_paddr_t xsdt_paddr, const uint8_t *sig)
 		return 0;
 	}
 
-	if (memcmp(xsdt->xsdt_hdr.sdth_sig, ACPI_XSDT_SIG,
-		   ACPI_SDTH_SIGLEN) != 0) {
+	if (memcmp(xsdt->Header.Signature, ACPI_SIG_XSDT,
+		   ACPI_NAME_SIZE) != 0) {
 		kprintf("sdt_search_xsdt: not XSDT\n");
 		goto back;
 	}
 
-	if (xsdt->xsdt_hdr.sdth_rev != 1) {
+	if (xsdt->Header.Revision != 1) {
 		kprintf("sdt_search_xsdt: unknown XSDT revision %d\n",
-			xsdt->xsdt_hdr.sdth_rev);
+			xsdt->Header.Revision);
 	}
 
-	if (xsdt->xsdt_hdr.sdth_len < sizeof(xsdt->xsdt_hdr)) {
+	if (xsdt->Header.Length < sizeof(xsdt->Header)) {
 		kprintf("sdt_search_xsdt: invalid XSDT length %u\n",
-			xsdt->xsdt_hdr.sdth_len);
+			xsdt->Header.Length);
 		goto back;
 	}
 
-	nent = (xsdt->xsdt_hdr.sdth_len - sizeof(xsdt->xsdt_hdr)) /
-	       sizeof(xsdt->xsdt_ents[0]);
+	nent = (xsdt->Header.Length - sizeof(xsdt->Header)) /
+	       sizeof(xsdt->TableOffsetEntry[0]);
 	for (i = 0; i < nent; ++i) {
-		struct acpi_sdth *sdth;
+		ACPI_TABLE_HEADER *sdth;
 
-		if (xsdt->xsdt_ents[i] == 0)
+		if (xsdt->TableOffsetEntry[i] == 0)
 			continue;
 
-		sdth = sdt_sdth_map(xsdt->xsdt_ents[i]);
+		sdth = sdt_sdth_map(xsdt->TableOffsetEntry[i]);
 		if (sdth != NULL) {
 			int ret;
 
-			ret = memcmp(sdth->sdth_sig, sig, ACPI_SDTH_SIGLEN);
+			ret = memcmp(sdth->Signature, sig, ACPI_NAME_SIZE);
 			sdt_sdth_unmap(sdth);
 
 			if (ret == 0) {
-				sdt_paddr = xsdt->xsdt_ents[i];
+				sdt_paddr = xsdt->TableOffsetEntry[i];
 				break;
 			}
 		}
 	}
 back:
-	sdt_sdth_unmap(&xsdt->xsdt_hdr);
+	sdt_sdth_unmap(&xsdt->Header);
 	return sdt_paddr;
 }
 
 static vm_paddr_t
 sdt_search_rsdt(vm_paddr_t rsdt_paddr, const uint8_t *sig)
 {
-	struct acpi_rsdt *rsdt;
+	ACPI_TABLE_RSDT *rsdt;
 	vm_paddr_t sdt_paddr = 0;
 	int i, nent;
 
@@ -258,46 +244,46 @@ sdt_search_rsdt(vm_paddr_t rsdt_paddr, const uint8_t *sig)
 		return 0;
 	}
 
-	if (memcmp(rsdt->rsdt_hdr.sdth_sig, ACPI_RSDT_SIG,
-		   ACPI_SDTH_SIGLEN) != 0) {
+	if (memcmp(rsdt->Header.Signature, ACPI_SIG_RSDT,
+		   ACPI_NAME_SIZE) != 0) {
 		kprintf("sdt_search_rsdt: not RSDT\n");
 		goto back;
 	}
 
-	if (rsdt->rsdt_hdr.sdth_rev != 1) {
+	if (rsdt->Header.Revision != 1) {
 		kprintf("sdt_search_rsdt: unknown RSDT revision %d\n",
-			rsdt->rsdt_hdr.sdth_rev);
+			rsdt->Header.Revision);
 	}
 
-	if (rsdt->rsdt_hdr.sdth_len < sizeof(rsdt->rsdt_hdr)) {
+	if (rsdt->Header.Length < sizeof(rsdt->Header)) {
 		kprintf("sdt_search_rsdt: invalid RSDT length %u\n",
-			rsdt->rsdt_hdr.sdth_len);
+			rsdt->Header.Length);
 		goto back;
 	}
 
-	nent = (rsdt->rsdt_hdr.sdth_len - sizeof(rsdt->rsdt_hdr)) /
-	       sizeof(rsdt->rsdt_ents[0]);
+	nent = (rsdt->Header.Length - sizeof(rsdt->Header)) /
+	       sizeof(rsdt->TableOffsetEntry[0]);
 	for (i = 0; i < nent; ++i) {
-		struct acpi_sdth *sdth;
+		ACPI_TABLE_HEADER *sdth;
 
-		if (rsdt->rsdt_ents[i] == 0)
+		if (rsdt->TableOffsetEntry[i] == 0)
 			continue;
 
-		sdth = sdt_sdth_map(rsdt->rsdt_ents[i]);
+		sdth = sdt_sdth_map(rsdt->TableOffsetEntry[i]);
 		if (sdth != NULL) {
 			int ret;
 
-			ret = memcmp(sdth->sdth_sig, sig, ACPI_SDTH_SIGLEN);
+			ret = memcmp(sdth->Signature, sig, ACPI_NAME_SIZE);
 			sdt_sdth_unmap(sdth);
 
 			if (ret == 0) {
-				sdt_paddr = rsdt->rsdt_ents[i];
+				sdt_paddr = rsdt->TableOffsetEntry[i];
 				break;
 			}
 		}
 	}
 back:
-	sdt_sdth_unmap(&rsdt->rsdt_hdr);
+	sdt_sdth_unmap(&rsdt->Header);
 	return sdt_paddr;
 }
 
diff --git a/sys/platform/pc64/acpica/acpi_sdt.h b/sys/platform/pc64/acpica/acpi_sdt.h
deleted file mode 100644
index d0b5c6e..0000000
--- a/sys/platform/pc64/acpica/acpi_sdt.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2009 The DragonFly Project.  All rights reserved.
- * 
- * This code is derived from software contributed to The DragonFly Project
- * by Sepherosa Ziehau <sepherosa@gmail.com>
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _ACPI_SDT_H_
-#define _ACPI_SDT_H_
-
-#define ACPI_SDTH_SIGLEN	4
-#define ACPI_RSDT_SIG		"RSDT"
-#define ACPI_XSDT_SIG		"XSDT"
-#define ACPI_MADT_SIG		"APIC"
-#define ACPI_FADT_SIG		"FACP"
-
-/* System Description Table Header */
-struct acpi_sdth {
-	uint8_t			sdth_sig[ACPI_SDTH_SIGLEN];
-	uint32_t		sdth_len;
-	uint8_t			sdth_rev;
-	uint8_t			sdth_cksum;
-	uint8_t			sdth_oem_id[6];
-	uint8_t			sdth_oem_tbid[8];
-	uint32_t		sdth_oem_rev;
-	uint32_t		sdth_crt_id;
-	uint32_t		sdth_crt_rev;
-} __packed;
-
-#endif	/* !_ACPI_SDT_H_ */
diff --git a/sys/platform/pc64/acpica/acpi_sdt_var.h b/sys/platform/pc64/acpica/acpi_sdt_var.h
index 2ca615c..1130864 100644
--- a/sys/platform/pc64/acpica/acpi_sdt_var.h
+++ b/sys/platform/pc64/acpica/acpi_sdt_var.h
@@ -1,8 +1,11 @@
 #ifndef _ACPI_SDT_VAR_H_
 #define _ACPI_SDT_VAR_H_
 
+#include <contrib/dev/acpica/source/include/acpi.h>
+#include <contrib/dev/acpica/source/include/actables.h>
+
 void		*sdt_sdth_map(vm_paddr_t);
-void		sdt_sdth_unmap(struct acpi_sdth *);
+void		sdt_sdth_unmap(ACPI_TABLE_HEADER *);
 
 vm_paddr_t	sdt_search(const uint8_t *);
 
-- 
1.8.2.2

