utmutex.c revision 26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0
/*******************************************************************************
*
* Module Name: utmutex - local mutex support
*
******************************************************************************/
/*
* Copyright (C) 2000 - 2011, Intel Corp.
* All rights reserved.
*
* 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,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* 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 MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR 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 DAMAGES.
*/
#define __UTMUTEX_C__
#include "acpi.h"
#include "accommon.h"
#define _COMPONENT ACPI_UTILITIES
ACPI_MODULE_NAME ("utmutex")
/* Local prototypes */
static ACPI_STATUS
static void
/*******************************************************************************
*
* FUNCTION: AcpiUtMutexInitialize
*
* PARAMETERS: None.
*
* RETURN: Status
*
* DESCRIPTION: Create the system mutex objects. This includes mutexes,
*
******************************************************************************/
void)
{
UINT32 i;
/* Create each of the predefined mutex objects */
for (i = 0; i < ACPI_NUM_MUTEX; i++)
{
Status = AcpiUtCreateMutex (i);
if (ACPI_FAILURE (Status))
{
}
}
/* Create the spinlocks for use at interrupt level */
if (ACPI_FAILURE (Status))
{
}
if (ACPI_FAILURE (Status))
{
}
/* Mutex for _OSI support */
if (ACPI_FAILURE (Status))
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiUtMutexTerminate
*
* PARAMETERS: None.
*
* RETURN: None.
*
* DESCRIPTION: Delete all of the system mutex objects. This includes mutexes,
*
******************************************************************************/
void
void)
{
UINT32 i;
/* Delete each predefined mutex object */
for (i = 0; i < ACPI_NUM_MUTEX; i++)
{
AcpiUtDeleteMutex (i);
}
/* Delete the spinlocks */
}
/*******************************************************************************
*
* FUNCTION: AcpiUtCreateMutex
*
* PARAMETERS: MutexID - ID of the mutex to be created
*
* RETURN: Status
*
* DESCRIPTION: Create a mutex object.
*
******************************************************************************/
static ACPI_STATUS
{
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiUtDeleteMutex
*
* PARAMETERS: MutexID - ID of the mutex to be deleted
*
* RETURN: Status
*
* DESCRIPTION: Delete a mutex object.
*
******************************************************************************/
static void
{
}
/*******************************************************************************
*
* FUNCTION: AcpiUtAcquireMutex
*
* PARAMETERS: MutexID - ID of the mutex to be acquired
*
* RETURN: Status
*
* DESCRIPTION: Acquire a mutex object.
*
******************************************************************************/
{
if (MutexId > ACPI_MAX_MUTEX)
{
return (AE_BAD_PARAMETER);
}
#ifdef ACPI_MUTEX_DEBUG
{
UINT32 i;
/*
* Mutex debug code, for internal debugging only.
*
* Deadlock prevention. Check if this thread owns any mutexes of value
* greater than or equal to this one. If so, the thread has violated
* the mutex ordering rule. This indicates a coding error somewhere in
* the ACPI subsystem code.
*/
for (i = MutexId; i < ACPI_NUM_MUTEX; i++)
{
{
if (i == MutexId)
{
"Mutex [%s] already acquired by this thread [%u]",
(UINT32) ThisThreadId));
return (AE_ALREADY_ACQUIRED);
}
"Invalid acquire order: Thread %u owns [%s], wants [%s]",
return (AE_ACQUIRE_DEADLOCK);
}
}
}
#endif
"Thread %u attempting to acquire Mutex [%s]\n",
if (ACPI_SUCCESS (Status))
{
}
else
{
"Thread %u could not acquire Mutex [0x%X]",
}
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtReleaseMutex
*
* PARAMETERS: MutexID - ID of the mutex to be released
*
* RETURN: Status
*
* DESCRIPTION: Release a mutex object.
*
******************************************************************************/
{
if (MutexId > ACPI_MAX_MUTEX)
{
return (AE_BAD_PARAMETER);
}
/*
* Mutex must be acquired in order to release it!
*/
{
"Mutex [0x%X] is not acquired, cannot release", MutexId));
return (AE_NOT_ACQUIRED);
}
#ifdef ACPI_MUTEX_DEBUG
{
UINT32 i;
/*
* Mutex debug code, for internal debugging only.
*
* Deadlock prevention. Check if this thread owns any mutexes of value
* greater than this one. If so, the thread has violated the mutex
* ordering rule. This indicates a coding error somewhere in
* the ACPI subsystem code.
*/
for (i = MutexId; i < ACPI_NUM_MUTEX; i++)
{
{
if (i == MutexId)
{
continue;
}
"Invalid release order: owns [%s], releasing [%s]",
return (AE_RELEASE_DEADLOCK);
}
}
}
#endif
/* Mark unlocked FIRST */
return (AE_OK);
}