From dfe948190b4c610d5a239340d8c4f1a0359264e4 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Tue, 20 May 2014 04:13:55 +0200
Subject: [PATCH] kernel/acpi: Sync a number of functions with FreeBSD.

AcpiOsReadPort()
AcpiOsWritePort()
AcpiOsReadPciConfiguration()
AcpiOsReadMemory()
AcpiOsWriteMemory()

According to the ACPI Programmer Reference, the data must be zero
extended to fill the return value even if the width of the location
is less than the return value's. Also clean up some unneeded default
cases.

This commit also fixes the messages we were getting:

acpi_tz0: _TMP value is absurd, ignored (-204.0C)
acpi_tz0: _TMP value is absurd, ignored (-203.0C)
acpi_tz0: _TMP value is absurd, ignored (-203.0C)
---
 sys/dev/acpica/Osd/OsdHardware.c | 24 ++++++------------------
 sys/dev/acpica/Osd/OsdMemory.c   | 30 ++++++++++++------------------
 2 files changed, 18 insertions(+), 36 deletions(-)

diff --git a/sys/dev/acpica/Osd/OsdHardware.c b/sys/dev/acpica/Osd/OsdHardware.c
index d3c16bb..41eac9b 100644
--- a/sys/dev/acpica/Osd/OsdHardware.c
+++ b/sys/dev/acpica/Osd/OsdHardware.c
@@ -62,20 +62,14 @@ 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);
+        *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);
+        *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);
+        *Value = bus_space_read_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort);
         break;
-    default:
-        /* debug trap goes here */
-	break;
     }
 
     return (AE_OK);
@@ -94,9 +88,6 @@ AcpiOsWritePort(ACPI_IO_ADDRESS OutPort, UINT32 Value, UINT32 Width)
     case 32:
         bus_space_write_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
         break;
-    default:
-        /* debug trap goes here */
-	break;
     }
 
     return (AE_OK);
@@ -106,17 +97,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);
 
-    *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);
 }
@@ -133,7 +121,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 fcb4197..c6800e8 100644
--- a/sys/dev/acpica/Osd/OsdMemory.c
+++ b/sys/dev/acpica/Osd/OsdMemory.c
@@ -224,29 +224,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 +253,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);
 }
-- 
1.8.5.2

