From: Daniel Walker <dwalker@mvista.com>
To: linux-acpi@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>,
len.brown@intel.com, ak@linux.intel.com
Subject: [PATCH 1/3] acpi: add real mutex function calls
Date: Sat, 19 Jul 2008 11:16:52 -0700 [thread overview]
Message-ID: <1216491411-24080-2-git-send-email-dwalker@mvista.com> (raw)
In-Reply-To: <1216491411-24080-1-git-send-email-dwalker@mvista.com>
Instead of re-using semaphores for the mutex operation, I've
added usage of the kernel mutex for the os mutex implementation.
Cc: len.brown@intel.com
Cc: linux-acpi@vger.kernel.org
Signed-off-by: Daniel Walker <dwalker@mvista.com>
---
drivers/acpi/osl.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++
include/acpi/acpiosxf.h | 11 +-----
2 files changed, 88 insertions(+), 9 deletions(-)
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 235a138..8546f59 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -871,6 +871,92 @@ acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
return AE_OK;
}
+acpi_status
+acpi_os_create_mutex(acpi_mutex *handle)
+{
+ struct mutex *mutex = NULL;
+
+ mutex = acpi_os_allocate(sizeof(struct mutex));
+ if (!mutex)
+ return AE_NO_MEMORY;
+ memset(mutex, 0, sizeof(struct mutex));
+
+ mutex_init(mutex);
+
+ *handle = (acpi_handle *) mutex;
+
+ ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating mutex[%p].\n",
+ *handle));
+
+ return AE_OK;
+}
+
+acpi_status acpi_os_delete_mutex(acpi_mutex handle)
+{
+ struct mutex *mutex = (struct mutex *)handle;
+
+ if (!mutex)
+ return AE_BAD_PARAMETER;
+
+ ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting mutex[%p].\n", handle));
+
+ BUG_ON(mutex_is_locked(mutex));
+ kfree(mutex);
+ mutex = NULL;
+
+ return AE_OK;
+}
+
+acpi_status acpi_os_acquire_mutex(acpi_mutex handle, u16 timeout)
+{
+ acpi_status status = AE_OK;
+ struct mutex *mutex = (struct mutex *)handle;
+ long jiffies;
+ int ret = 0;
+
+ if (!mutex)
+ return AE_BAD_PARAMETER;
+
+ ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for mutex[%p|%d]\n",
+ handle, timeout));
+
+ if (timeout == ACPI_WAIT_FOREVER)
+ jiffies = MAX_SCHEDULE_TIMEOUT;
+ else
+ jiffies = msecs_to_jiffies(timeout);
+
+ ret = mutex_lock_interruptible_nested(mutex);
+ if (ret == -EINTR)
+ status = AE_TIME;
+
+ if (ACPI_FAILURE(status)) {
+ ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
+ "Failed to acquire mutex[%p|%d], %s",
+ handle, timeout,
+ acpi_format_exception(status)));
+ } else {
+ ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
+ "Acquired mutex[%p|%d]", handle,
+ timeout));
+ }
+
+ return status;
+}
+
+acpi_status acpi_os_release_mutex(acpi_mutex handle)
+{
+ struct mutex *mutex = (struct mutex *)handle;
+
+ if (!mutex)
+ return AE_BAD_PARAMETER;
+
+ ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling mutex[%p]\n", handle));
+
+ mutex_unlock(mutex);
+
+ return AE_OK;
+}
+
#ifdef ACPI_FUTURE_USAGE
u32 acpi_os_get_line(char *buffer)
{
diff --git a/include/acpi/acpiosxf.h b/include/acpi/acpiosxf.h
index 3f93a6b..9032ec3 100644
--- a/include/acpi/acpiosxf.h
+++ b/include/acpi/acpiosxf.h
@@ -125,18 +125,11 @@ acpi_status acpi_os_signal_semaphore(acpi_semaphore handle, u32 units);
*/
acpi_status acpi_os_create_mutex(acpi_mutex * out_handle);
-void acpi_os_delete_mutex(acpi_mutex handle);
+acpi_status acpi_os_delete_mutex(acpi_mutex handle);
acpi_status acpi_os_acquire_mutex(acpi_mutex handle, u16 timeout);
-void acpi_os_release_mutex(acpi_mutex handle);
-
-/* Temporary macros for Mutex* interfaces, map to existing semaphore xfaces */
-
-#define acpi_os_create_mutex(out_handle) acpi_os_create_semaphore (1, 1, out_handle)
-#define acpi_os_delete_mutex(handle) (void) acpi_os_delete_semaphore (handle)
-#define acpi_os_acquire_mutex(handle,time) acpi_os_wait_semaphore (handle, 1, time)
-#define acpi_os_release_mutex(handle) (void) acpi_os_signal_semaphore (handle, 1)
+acpi_status acpi_os_release_mutex(acpi_mutex handle);
/*
* Memory allocation and mapping
--
1.5.5.1.32.gba7d2
next prev parent reply other threads:[~2008-07-19 18:17 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-19 18:16 [PATCH 0/3] acpi: acpi: sem out, mutex/completion in Daniel Walker
2008-07-19 18:16 ` Daniel Walker [this message]
2008-07-19 18:16 ` [PATCH 2/3] acpi: semaphore removal Daniel Walker
2008-07-19 18:16 ` [PATCH 3/3] Add lockdep integration for the ACPI mutex usage Daniel Walker
2008-07-20 8:15 ` [PATCH 2/3] acpi: semaphore removal Dave Chinner
2008-07-20 14:49 ` Daniel Walker
2008-07-21 1:51 ` [PATCH 1/3] acpi: add real mutex function calls Zhao Yakui
2008-07-21 9:14 ` Peter Zijlstra
2008-07-21 9:17 ` Andi Kleen
2008-07-21 9:24 ` Peter Zijlstra
2008-07-21 19:15 ` Andi Kleen
2008-07-21 19:33 ` Peter Zijlstra
2008-07-21 19:55 ` Matthew Wilcox
2008-07-21 20:22 ` Daniel Walker
2008-07-21 20:00 ` Andi Kleen
2008-07-21 20:38 ` Daniel Walker
2008-07-21 13:59 ` Daniel Walker
2008-07-21 13:56 ` Daniel Walker
2008-07-21 19:20 ` Andi Kleen
2008-07-21 19:39 ` Daniel Walker
2008-07-23 22:14 ` Moore, Robert
2008-07-24 12:44 ` Daniel Walker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1216491411-24080-2-git-send-email-dwalker@mvista.com \
--to=dwalker@mvista.com \
--cc=ak@linux.intel.com \
--cc=len.brown@intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox