From d2d6956156e85f68b36b9c81016cb7399f4a0eb8 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Mon, 10 Feb 2014 21:30:35 +0100
Subject: [PATCH] WIP kernel/acpi: Bring in some miscellaneous changes from
 FreeBSD and clean up acdragonfly.h too.

---
 sys/dev/acpica/Osd/OsdDebug.c    |  39 ++++-----
 sys/dev/acpica/Osd/OsdHardware.c |  59 +++++--------
 sys/dev/acpica/Osd/OsdMemory.c   | 174 ++++-----------------------------------
 sys/dev/acpica/Osd/OsdTable.c    |  42 ++++++----
 sys/dev/acpica/acdragonfly.h     |  47 +++++------
 sys/platform/pc32/include/pmap.h |   2 +
 sys/platform/pc64/include/pmap.h |   2 +
 7 files changed, 104 insertions(+), 261 deletions(-)

diff --git a/sys/dev/acpica/Osd/OsdDebug.c b/sys/dev/acpica/Osd/OsdDebug.c
index 5b3d79f..297cb09 100644
--- a/sys/dev/acpica/Osd/OsdDebug.c
+++ b/sys/dev/acpica/Osd/OsdDebug.c
@@ -24,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/acpica/Osd/OsdDebug.c,v 1.9 2004/09/02 04:28:05 njl Exp $
+ * $FreeBSD: head/sys/dev/acpica/Osd/OsdDebug.c 222544 2011-05-31 19:45:58Z jkim $
  */
 
 /*
@@ -48,32 +48,22 @@ ACPI_STATUS
 AcpiOsGetLine(char *Buffer, UINT32 BufferLength, UINT32 *BytesRead)
 {
 #ifdef DDB
-    char *cp;
+	char *cp;
 
-    cp = Buffer;
-    if (db_readline(Buffer, BufferLength) > 0)
-        while (*cp != '\0' && *cp != '\n' && *cp != '\r')
-            cp++;
-    *cp = '\0';
-    if (BytesRead != NULL)
-        *BytesRead = cp - Buffer;
-    return (AE_OK);
+	cp = Buffer;
+	if (db_readline(Buffer, BufferLength) > 0)
+		while (*cp != '\0' && *cp != '\n' && *cp != '\r')
+			cp++;
+	*cp = '\0';
+	if (BytesRead != NULL)
+		*BytesRead = cp - Buffer;
+	return (AE_OK);
 #else
-    kprintf("AcpiOsGetLine called but no input support");
-    return (AE_NOT_EXIST);
+	kprintf("AcpiOsGetLine called but no input support");
+	return (AE_NOT_EXIST);
 #endif /* DDB */
 }
 
-#if 0	/* unused for ages */
-void
-AcpiOsDbgAssert(void *FailedAssertion, void *FileName, UINT32 LineNumber,
-    char *Message)
-{
-    kprintf("ACPI: %s:%d - %s\n", (char *)FileName, LineNumber, Message);
-    kprintf("ACPI: assertion  %s\n", (char *)FailedAssertion);
-}
-#endif
-
 ACPI_STATUS
 AcpiOsSignal(UINT32 Function, void *Info)
 {
@@ -82,9 +72,11 @@ AcpiOsSignal(UINT32 Function, void *Info)
     switch (Function) {
     case ACPI_SIGNAL_FATAL:
 	fatal = (ACPI_SIGNAL_FATAL_INFO *)Info;
-	kprintf("ACPI fatal signal, type 0x%x  code 0x%x  argument 0x%x",
+	kprintf("ACPI fatal signal, type 0x%x code 0x%x argument 0x%x",
 	      fatal->Type, fatal->Code, fatal->Argument);
+#ifdef ACPI_DEBUG
 	Debugger("AcpiOsSignal");
+#endif
 	break;
 	
     case ACPI_SIGNAL_BREAKPOINT:
@@ -96,6 +88,7 @@ AcpiOsSignal(UINT32 Function, void *Info)
     default:
 	return (AE_BAD_PARAMETER);
     }
+
     return (AE_OK);
 }
 
diff --git a/sys/dev/acpica/Osd/OsdHardware.c b/sys/dev/acpica/Osd/OsdHardware.c
index 938a854..674c311 100644
--- a/sys/dev/acpica/Osd/OsdHardware.c
+++ b/sys/dev/acpica/Osd/OsdHardware.c
@@ -24,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/acpica/Osd/OsdHardware.c,v 1.13 2004/04/14 03:39:08 njl Exp $
+ * $FreeBSD: head/sys/dev/acpica/Osd/OsdHardware.c 213787 2010-10-13 17:06:25Z jkim $
  */
 
 /*
@@ -35,13 +35,12 @@
 
 #include <sys/bus.h>
 #include <bus/pci/pci_cfgreg.h>
-#include <bus/pci/pcireg.h>
 
 /*
  * ACPICA's rather gung-ho approach to hardware resource ownership is a little
- * troublesome insofar as there is no easy way for us to know in advance 
+ * troublesome insofar as there is no easy way for us to know in advance
  * exactly which I/O resources it's going to want to use.
- * 
+ *
  * In order to deal with this, we ignore resource ownership entirely, and simply
  * use the native I/O space accessor functionality.  This is Evil, but it works.
  *
@@ -49,16 +48,12 @@
  */
 
 #ifdef __i386__
-#define ACPI_BUS_SPACE_IO	I386_BUS_SPACE_IO
-#define ACPI_BUS_HANDLE		0
-#endif
-#ifdef __ia64__
-#define ACPI_BUS_SPACE_IO	IA64_BUS_SPACE_IO
-#define ACPI_BUS_HANDLE		0
+#define	ACPI_BUS_SPACE_IO	I386_BUS_SPACE_IO
+#define	ACPI_BUS_HANDLE		0
 #endif
 #ifdef __x86_64__
-#define ACPI_BUS_SPACE_IO	X86_64_BUS_SPACE_IO
-#define ACPI_BUS_HANDLE		0
+#define	ACPI_BUS_SPACE_IO	X86_64_BUS_SPACE_IO
+#define	ACPI_BUS_HANDLE		0
 #endif
 
 ACPI_STATUS
@@ -66,19 +61,13 @@ AcpiOsReadPort(ACPI_IO_ADDRESS InPort, UINT32 *Value, UINT32 Width)
 {
     switch (Width) {
     case 8:
-        *(u_int8_t *)Value = bus_space_read_1(ACPI_BUS_SPACE_IO,
-	    ACPI_BUS_HANDLE, InPort);
-        break;
+	*Value = bus_space_read_1(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort);
+	break;
     case 16:
-        *(u_int16_t *)Value = bus_space_read_2(ACPI_BUS_SPACE_IO,
-	    ACPI_BUS_HANDLE, InPort);
-        break;
+	*Value = bus_space_read_2(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort);
+	break;
     case 32:
-        *(u_int32_t *)Value = bus_space_read_4(ACPI_BUS_SPACE_IO,
-	    ACPI_BUS_HANDLE, InPort);
-        break;
-    default:
-        /* debug trap goes here */
+	*Value = bus_space_read_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort);
 	break;
     }
 
@@ -90,16 +79,13 @@ AcpiOsWritePort(ACPI_IO_ADDRESS OutPort, UINT32 Value, UINT32 Width)
 {
     switch (Width) {
     case 8:
-        bus_space_write_1(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
-        break;
+	bus_space_write_1(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
+	break;
     case 16:
-        bus_space_write_2(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
-        break;
+	bus_space_write_2(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
+	break;
     case 32:
-        bus_space_write_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
-        break;
-    default:
-        /* debug trap goes here */
+	bus_space_write_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
 	break;
     }
 
@@ -110,17 +96,14 @@ ACPI_STATUS
 AcpiOsReadPciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register, UINT64 *Value,
     UINT32 Width)
 {
-    int bytes = Width / 8;
-
     if (Width == 64)
 	return (AE_SUPPORT);
 
     if (!pci_cfgregopen())
-        return (AE_NOT_EXIST);
+	return (AE_NOT_EXIST);
 
-    *Value = pci_cfgregread(PciId->Bus, PciId->Device,
-    				      PciId->Function, Register, bytes);
-    *Value &= (1 << (bytes * 8)) - 1;
+    *(UINT64 *)Value = pci_cfgregread(PciId->Bus, PciId->Device,
+	PciId->Function, Register, Width / 8);
 
     return (AE_OK);
 }
@@ -137,7 +120,7 @@ AcpiOsWritePciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register,
     	return (AE_NOT_EXIST);
 
     pci_cfgregwrite(PciId->Bus, PciId->Device, PciId->Function, Register,
-    		    (u_int32_t)Value, Width / 8); /* XXX casting */
+	Value, Width / 8);
 
     return (AE_OK);
 }
diff --git a/sys/dev/acpica/Osd/OsdMemory.c b/sys/dev/acpica/Osd/OsdMemory.c
index e939c58..e750303 100644
--- a/sys/dev/acpica/Osd/OsdMemory.c
+++ b/sys/dev/acpica/Osd/OsdMemory.c
@@ -25,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/acpica/Osd/OsdMemory.c,v 1.11 2004/04/14 03:39:08 njl Exp $
+ * $FreeBSD: head/sys/dev/acpica/Osd/OsdMemory.c 231844 2012-02-16 22:59:29Z jkim $
  */
 
 /*
@@ -39,24 +39,7 @@
 #include <vm/vm.h>
 #include <vm/pmap.h>
 
-MALLOC_DEFINE(M_ACPICA, "acpica", "ACPI CA memory pool");
-
-struct acpi_memtrack {
-    struct acpi_memtrack *next;
-    void *base;
-    ACPI_SIZE size;
-#ifdef ACPI_DEBUG_MEMMAP
-    int freed;
-    struct {
-	const char *func;
-	int line;
-    } mapper, unmapper;
-#endif
-};
-
-typedef struct acpi_memtrack *acpi_memtrack_t;
-
-static acpi_memtrack_t acpi_mapbase;
+static MALLOC_DEFINE(M_ACPICA, "acpica", "ACPI CA memory pool");
 
 void *
 AcpiOsAllocate(ACPI_SIZE Size)
@@ -70,129 +53,16 @@ AcpiOsFree(void *Memory)
     kfree(Memory, M_ACPICA);
 }
 
-#ifdef ACPI_DEBUG_MEMMAP
-void *
-_AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS Where, ACPI_SIZE Length,
-		 const char *caller, int line)
-#else
 void *
-AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS Where, ACPI_SIZE Length)
-#endif
+AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length)
 {
-    acpi_memtrack_t track;
-    void *map;
-
-    map = pmap_mapdev((vm_offset_t)Where, Length);
-    if (map == NULL)
-	return(NULL);
-    else {
-#ifdef ACPI_DEBUG_MEMMAP
-	for (track = acpi_mapbase; track != NULL; track = track->next) {
-	    if (track->base == map)
-		break;
-	}
-#else
-	track = NULL;
-#endif
-	if (track == NULL) {
-	    track = kmalloc(sizeof(*track), M_ACPICA, M_INTWAIT);
-	    track->next = acpi_mapbase;
-	    track->base = map;
-	}
-	track->size = Length;
-#ifdef ACPI_DEBUG_MEMMAP
-	track->freed = 0;
-	track->mapper.func = caller;
-	track->mapper.line = line;
-	track->unmapper.func = "";
-	track->unmapper.line = 0;
-#endif
-	acpi_mapbase = track;
-    }
-    return(map);
+    return (pmap_mapbios((vm_offset_t)PhysicalAddress, Length));
 }
 
-#ifdef ACPI_DEBUG_MEMMAP
-void
-_AcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Length,
-		   const char *caller, int line)
-#else
 void
 AcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Length)
-#endif
 {
-    struct acpi_memtrack **ptrack;
-    acpi_memtrack_t track;
-
-again:
-    for (ptrack = &acpi_mapbase; (track = *ptrack); ptrack = &track->next) {
-#ifdef ACPI_DEBUG_MEMMAP
-	if (track->freed)
-	    continue;
-#endif
-	/*
-	 * Exact match, degenerate case
-	 */
-	if (track->base == LogicalAddress && track->size == Length) {
-	    *ptrack = track->next;
-	    pmap_unmapdev((vm_offset_t)track->base, track->size);
-#ifdef ACPI_DEBUG_MEMMAP
-	    track->freed = 1;
-	    track->unmapper.func = caller;
-	    track->unmapper.line = line;
-#else
-	    kfree(track, M_ACPICA);
-#endif
-	    return;
-	}
-	/*
-	 * Completely covered
-	 */
-	if ((char *)LogicalAddress <= (char *)track->base &&
-	    (char *)LogicalAddress + Length >= (char *)track->base + track->size
-	) {
-	    *ptrack = track->next;
-	    pmap_unmapdev((vm_offset_t)track->base, track->size);
-	    kprintf("AcpiOsUnmapMemory: Warning, deallocation request too"
-		   " large! %p/%08jx (actual was %p/%08jx)\n",
-		   LogicalAddress, (intmax_t)Length,
-		   track->base, (intmax_t)track->size);
-#ifdef ACPI_DEBUG_MEMMAP
-	    track->freed = 1;
-	    track->unmapper.func = caller;
-	    track->unmapper.line = line;
-#else
-	    kfree(track, M_ACPICA);
-#endif
-	    goto again;
-	}
-
-	/*
-	 * Overlapping
-	 */
-	if ((char *)LogicalAddress + Length >= (char *)track->base &&
-	    (char *)LogicalAddress < (char *)track->base + track->size
-	) {
-	    kprintf("AcpiOsUnmapMemory: Warning, deallocation did not "
-		   "track allocation: %p/%08jx (actual was %p/%08jx)\n",
-		   LogicalAddress, (intmax_t)Length,
-		   track->base, (intmax_t)track->size);
-	}
-    }
-    kprintf("AcpiOsUnmapMemory: Warning, broken ACPI, bad unmap: %p/%08jx\n",
-	    LogicalAddress, (intmax_t)Length);
-#ifdef ACPI_DEBUG_MEMMAP
-    for (track = acpi_mapbase; track != NULL; track = track->next) {
-	if (track->freed && track->base == LogicalAddress) {
-	    kprintf("%s: unmapping: %p/%08x, mapped by %s:%d,"
-		   "last unmapped by %s:%d\n",
-		__func__, LogicalAddress, Length,
-		track->mapper.func, track->mapper.line,
-		track->unmapper.func, track->unmapper.line
-	    );
-	}
-    }
-#endif
+    pmap_unmapbios((vm_offset_t)LogicalAddress, Length);
 }
 
 ACPI_STATUS
@@ -203,10 +73,6 @@ AcpiOsGetPhysicalAddress(void *LogicalAddress,
     return (AE_BAD_ADDRESS);
 }
 
-/*
- * There is no clean way to do this.  We make the charitable assumption
- * that callers will not pass garbage to us.
- */
 BOOLEAN
 AcpiOsReadable (void *Pointer, ACPI_SIZE Length)
 {
@@ -224,29 +90,26 @@ AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address, UINT64 *Value, UINT32 Width)
 {
     void	*LogicalAddress;
 
-    LogicalAddress = AcpiOsMapMemory(Address, Width / 8);
+    LogicalAddress = pmap_mapdev(Address, Width / 8);
     if (LogicalAddress == NULL)
 	return (AE_NOT_EXIST);
 
     switch (Width) {
     case 8:
-	*(u_int8_t *)Value = (*(volatile u_int8_t *)LogicalAddress);
+	*Value = *(volatile uint8_t *)LogicalAddress;
 	break;
     case 16:
-	*(u_int16_t *)Value = (*(volatile u_int16_t *)LogicalAddress);
+	*Value = *(volatile uint16_t *)LogicalAddress;
 	break;
     case 32:
-	*(u_int32_t *)Value = (*(volatile u_int32_t *)LogicalAddress);
+	*Value = *(volatile uint32_t *)LogicalAddress;
 	break;
     case 64:
-	*(u_int64_t *)Value = (*(volatile u_int64_t *)LogicalAddress);
-	break;
-    default:
-	/* debug trap goes here */
+	*Value = *(volatile uint64_t *)LogicalAddress;
 	break;
     }
 
-    AcpiOsUnmapMemory(LogicalAddress, Width / 8);
+    pmap_unmapdev((vm_offset_t)LogicalAddress, Width / 8);
 
     return (AE_OK);
 }
@@ -256,29 +119,26 @@ AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address, UINT64 Value, UINT32 Width)
 {
     void	*LogicalAddress;
 
-    LogicalAddress = AcpiOsMapMemory(Address, Width / 8);
+    LogicalAddress = pmap_mapdev(Address, Width / 8);
     if (LogicalAddress == NULL)
 	return (AE_NOT_EXIST);
 
     switch (Width) {
     case 8:
-	(*(volatile u_int8_t *)LogicalAddress) = Value & 0xff;
+	*(volatile uint8_t *)LogicalAddress = Value;
 	break;
     case 16:
-	(*(volatile u_int16_t *)LogicalAddress) = Value & 0xffff;
+	*(volatile uint16_t *)LogicalAddress = Value;
 	break;
     case 32:
-	(*(volatile u_int32_t *)LogicalAddress) = Value & 0xffffffff;
+	*(volatile uint32_t *)LogicalAddress = Value;
 	break;
     case 64:
-	(*(volatile u_int64_t *)LogicalAddress) = Value;
-	break;
-    default:
-	/* debug trap goes here */
+	*(volatile uint64_t *)LogicalAddress = Value;
 	break;
     }
 
-    AcpiOsUnmapMemory(LogicalAddress, Width / 8);
+    pmap_unmapdev((vm_offset_t)LogicalAddress, Width / 8);
 
     return (AE_OK);
 }
diff --git a/sys/dev/acpica/Osd/OsdTable.c b/sys/dev/acpica/Osd/OsdTable.c
index 65ae373..1f3862a 100644
--- a/sys/dev/acpica/Osd/OsdTable.c
+++ b/sys/dev/acpica/Osd/OsdTable.c
@@ -23,39 +23,42 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/acpica/Osd/OsdTable.c,v 1.7 2004/04/20 17:13:08 njl Exp $
+ * $FreeBSD: head/sys/dev/acpica/Osd/OsdTable.c 250838 2013-05-20 23:52:49Z jkim $
  */
 
 /*
  * ACPI Table interfaces
  */
 
-#include "acpi.h"
-
+#include <sys/param.h>
+#include <sys/endian.h>
 #include <sys/kernel.h>
 #include <sys/linker.h>
 
+#include "acpi.h"
+#include "actables.h"
+
 #undef _COMPONENT
-#define _COMPONENT      ACPI_TABLES
+#define	_COMPONENT      ACPI_TABLES
 
 static char acpi_osname[128];
 TUNABLE_STR("hw.acpi.osname", acpi_osname, sizeof(acpi_osname));
 
 ACPI_STATUS
-AcpiOsPredefinedOverride (
-    const ACPI_PREDEFINED_NAMES *InitVal,
-    ACPI_STRING                 *NewVal)
+AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal,
+    ACPI_STRING *NewVal)
 {
-    if (InitVal == NULL || NewVal == NULL)
-	return (AE_BAD_PARAMETER);
-
-    *NewVal = NULL;
-    if (strncmp(InitVal->Name, "_OS_", 4) == 0 && strlen(acpi_osname) > 0) {
-	kprintf("ACPI: Overriding _OS definition with \"%s\"\n", acpi_osname);
-	*NewVal = acpi_osname;
-    }
+	if (InitVal == NULL || NewVal == NULL)
+		return (AE_BAD_PARAMETER);
 
-    return (AE_OK);
+	*NewVal = NULL;
+	if (ACPI_COMPARE_NAME(InitVal->Name, "_OS_") &&
+	    InitVal->Type == ACPI_TYPE_STRING && strlen(acpi_osname) > 0) {
+		kprintf("ACPI: Overriding _OS definition with \"%s\"\n",
+		    acpi_osname);
+		*NewVal = acpi_osname;
+	}
+	return (AE_OK);
 }
 
 ACPI_STATUS
@@ -80,3 +83,10 @@ AcpiOsTableOverride (
     kprintf("ACPI: DSDT was overridden.\n");
     return (AE_OK);
 }
+
+ACPI_STATUS
+AcpiOsPhysicalTableOverride(ACPI_TABLE_HEADER *ExistingTable,
+    ACPI_PHYSICAL_ADDRESS *NewAddress, UINT32 *NewTableLength)
+{
+	return (AE_OK);
+}
diff --git a/sys/dev/acpica/acdragonfly.h b/sys/dev/acpica/acdragonfly.h
index fe3fa28..47d4ec4 100644
--- a/sys/dev/acpica/acdragonfly.h
+++ b/sys/dev/acpica/acdragonfly.h
@@ -117,10 +117,8 @@
 #ifndef __ACDRAGONFLY_H_
 #define __ACDRAGONFLY_H_
 
-/* DragonFly uses GCC */
-
+#include <platform/acgcc.h>	/* DragonFly uses GCC */
 #include <sys/types.h>
-#include <platform/acgcc.h>
 #include <machine/acpica_machdep.h>
 
 #define ACPI_UINTPTR_T		uintptr_t
@@ -129,10 +127,7 @@
 #include "opt_acpi.h"
 #endif
 
-#ifdef ACPI_DEBUG
-#define ACPI_DEBUG_OUTPUT	/* for backward compatibility */
-#define ACPI_DISASSEMBLER
-#endif
+#define ACPI_USE_DO_WHILE_0
 
 #ifdef _KERNEL
 
@@ -148,6 +143,11 @@
 
 #define DEBUGGER_THREADING 0    /* integrated with DDB */
 
+#ifdef ACPI_DEBUG
+#define ACPI_DEBUG_OUTPUT	/* for backward compatibility */
+#define ACPI_DISASSEMBLER
+#endif
+
 #ifdef ACPI_DEBUG_OUTPUT
 #include "opt_ddb.h"
 #ifdef DDB
@@ -163,25 +163,8 @@ struct acpi_spinlock;
 struct acpicache;
 #endif
 
-#else /* _KERNEL */
-
-#define ACPI_CAST_PTHREAD_T(pthread)    ((ACPI_THREAD_ID) ACPI_TO_INTEGER (pthread))
-
-/* Always use DragonFly code over our local versions */
-#define ACPI_USE_SYSTEM_CLIBRARY
-
-/* Not building kernel code, so use libc */
-#define ACPI_USE_STANDARD_HEADERS
-#define ACPI_FLUSH_CPU_CACHE()
-#define __cli()
-#define __sti()
-
-#endif /* _KERNEL */
-
-#ifdef _KERNEL
-
 /* Or strstr (used in debugging mode, also move to libkern) */
-static __inline char *
+static inline char *
 strstr(char *s, char *find)
 {
     char c, sc;
@@ -199,8 +182,18 @@ strstr(char *s, char *find)
     }
     return (s);
 }
-#endif /* _KERNEL */
 
-#define inline		__inline
+#else /* _KERNEL */
+
+/* Always use DragonFly code over our local versions */
+#define ACPI_USE_SYSTEM_CLIBRARY
+
+#define ACPI_CAST_PTHREAD_T(pthread)    ((ACPI_THREAD_ID) ACPI_TO_INTEGER (pthread))
+
+/* Not building kernel code, so use libc */
+#define ACPI_USE_STANDARD_HEADERS
+#define ACPI_FLUSH_CPU_CACHE()
+
+#endif /* _KERNEL */
 
 #endif /* __ACDRAGONFLY_H_ */
diff --git a/sys/platform/pc32/include/pmap.h b/sys/platform/pc32/include/pmap.h
index f168a32..33ae23a 100644
--- a/sys/platform/pc32/include/pmap.h
+++ b/sys/platform/pc32/include/pmap.h
@@ -306,6 +306,8 @@ extern char *ptvmmap;		/* poor name! */
 typedef struct vm_page *vm_page_t;
 typedef char vm_memattr_t;
 
+#define	pmap_unmapbios(va, sz)	pmap_unmapdev((va), (sz))
+
 void	pmap_release(struct pmap *pmap);
 void	pmap_interlock_wait (struct vmspace *);
 void	pmap_bootstrap (vm_paddr_t, vm_paddr_t);
diff --git a/sys/platform/pc64/include/pmap.h b/sys/platform/pc64/include/pmap.h
index cc413dc..3f59e5f 100644
--- a/sys/platform/pc64/include/pmap.h
+++ b/sys/platform/pc64/include/pmap.h
@@ -354,6 +354,8 @@ extern char *ptvmmap;		/* poor name! */
 typedef struct vm_page *vm_page_t;
 typedef char vm_memattr_t;
 
+#define	pmap_unmapbios(va, sz)	pmap_unmapdev((va), (sz))
+
 void	pmap_release(struct pmap *pmap);
 void	pmap_interlock_wait (struct vmspace *);
 void	pmap_bootstrap (vm_paddr_t *);
-- 
1.8.4.3

