From 3bd12ca8f16af8e8ba3222f834c8df7ba2e3e230 Mon Sep 17 00:00:00 2001
From: Jung-uk Kim <jkim@FreeBSD.org>
Date: Tue, 13 Aug 2013 21:34:03 +0000
Subject: [PATCH] Tidy up global locks for ACPICA.  There is no functional
 change.

---
 sys/amd64/include/acpica_machdep.h |  6 +++---
 sys/dev/acpica/Osd/OsdSynch.c      | 22 ++++++++++------------
 sys/i386/include/acpica_machdep.h  |  6 +++---
 sys/ia64/include/acpica_machdep.h  |  6 +++---
 4 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/sys/amd64/include/acpica_machdep.h b/sys/amd64/include/acpica_machdep.h
index eb0282aa75b9..474378685892 100644
--- a/sys/amd64/include/acpica_machdep.h
+++ b/sys/amd64/include/acpica_machdep.h
@@ -59,9 +59,9 @@
 
 #define	ACPI_FLUSH_CPU_CACHE()	wbinvd()
 
-/* Section 5.2.9.1:  global lock acquire/release functions */
-extern int	acpi_acquire_global_lock(uint32_t *lock);
-extern int	acpi_release_global_lock(uint32_t *lock);
+/* Section 5.2.10.1: global lock acquire/release functions */
+int	acpi_acquire_global_lock(volatile uint32_t *);
+int	acpi_release_global_lock(volatile uint32_t *);
 #define	ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq)	do {			\
 	(Acq) = acpi_acquire_global_lock(&((GLptr)->GlobalLock));	\
 } while (0)
diff --git a/sys/dev/acpica/Osd/OsdSynch.c b/sys/dev/acpica/Osd/OsdSynch.c
index b70a12051ee7..99a69ec7752c 100644
--- a/sys/dev/acpica/Osd/OsdSynch.c
+++ b/sys/dev/acpica/Osd/OsdSynch.c
@@ -566,8 +566,6 @@ AcpiOsReleaseLock(ACPI_SPINLOCK Handle, ACPI_CPU_FLAGS Flags)
 }
 
 /* Section 5.2.10.1: global lock acquire/release functions */
-#define	GL_BIT_PENDING	0x01
-#define	GL_BIT_OWNED	0x02
 
 /*
  * Acquire the global lock.  If busy, set the pending bit.  The caller
@@ -575,18 +573,18 @@ AcpiOsReleaseLock(ACPI_SPINLOCK Handle, ACPI_CPU_FLAGS Flags)
  * and then attempt to acquire it again.
  */
 int
-acpi_acquire_global_lock(uint32_t *lock)
+acpi_acquire_global_lock(volatile uint32_t *lock)
 {
 	uint32_t	new, old;
 
 	do {
 		old = *lock;
-		new = (old & ~GL_BIT_PENDING) | GL_BIT_OWNED;
-		if ((old & GL_BIT_OWNED) != 0)
-			new |= GL_BIT_PENDING;
-	} while (atomic_cmpset_acq_int(lock, old, new) == 0);
+		new = (old & ~ACPI_GLOCK_PENDING) | ACPI_GLOCK_OWNED;
+		if ((old & ACPI_GLOCK_OWNED) != 0)
+			new |= ACPI_GLOCK_PENDING;
+	} while (atomic_cmpset_32(lock, old, new) == 0);
 
-	return ((new & GL_BIT_PENDING) == 0);
+	return ((new & ACPI_GLOCK_PENDING) == 0);
 }
 
 /*
@@ -595,14 +593,14 @@ acpi_acquire_global_lock(uint32_t *lock)
  * releases the lock.
  */
 int
-acpi_release_global_lock(uint32_t *lock)
+acpi_release_global_lock(volatile uint32_t *lock)
 {
 	uint32_t	new, old;
 
 	do {
 		old = *lock;
-		new = old & ~(GL_BIT_PENDING | GL_BIT_OWNED);
-	} while (atomic_cmpset_rel_int(lock, old, new) == 0);
+		new = old & ~(ACPI_GLOCK_PENDING | ACPI_GLOCK_OWNED);
+	} while (atomic_cmpset_32(lock, old, new) == 0);
 
-	return ((old & GL_BIT_PENDING) != 0);
+	return ((old & ACPI_GLOCK_PENDING) != 0);
 }
diff --git a/sys/i386/include/acpica_machdep.h b/sys/i386/include/acpica_machdep.h
index c4419f26f684..07bc167a4bbc 100644
--- a/sys/i386/include/acpica_machdep.h
+++ b/sys/i386/include/acpica_machdep.h
@@ -59,9 +59,9 @@
 
 #define	ACPI_FLUSH_CPU_CACHE()	wbinvd()
 
-/* Section 5.2.9.1:  global lock acquire/release functions */
-extern int	acpi_acquire_global_lock(uint32_t *lock);
-extern int	acpi_release_global_lock(uint32_t *lock);
+/* Section 5.2.10.1: global lock acquire/release functions */
+int	acpi_acquire_global_lock(volatile uint32_t *);
+int	acpi_release_global_lock(volatile uint32_t *);
 #define	ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq)	do {			\
 	(Acq) = acpi_acquire_global_lock(&((GLptr)->GlobalLock));	\
 } while (0)
diff --git a/sys/ia64/include/acpica_machdep.h b/sys/ia64/include/acpica_machdep.h
index f64ab8f6c4bb..2f861e847b3e 100644
--- a/sys/ia64/include/acpica_machdep.h
+++ b/sys/ia64/include/acpica_machdep.h
@@ -60,9 +60,9 @@
 
 #define	ACPI_FLUSH_CPU_CACHE()	/* XXX ia64_fc()? */
 
-/* Section 5.2.9.1:  global lock acquire/release functions */
-extern int	acpi_acquire_global_lock(uint32_t *lock);
-extern int	acpi_release_global_lock(uint32_t *lock);
+/* Section 5.2.10.1: global lock acquire/release functions */
+int	acpi_acquire_global_lock(volatile uint32_t *);
+int	acpi_release_global_lock(volatile uint32_t *);
 #define	ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq)	do {			\
 	(Acq) = acpi_acquire_global_lock(&((GLptr)->GlobalLock));	\
 } while (0)