ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

evglock.c
Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * Module Name: evglock - Global Lock support
00004  *
00005  *****************************************************************************/
00006 
00007 /******************************************************************************
00008  *
00009  * 1. Copyright Notice
00010  *
00011  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
00012  * All rights reserved.
00013  *
00014  * 2. License
00015  *
00016  * 2.1. This is your license from Intel Corp. under its intellectual property
00017  * rights.  You may have additional license terms from the party that provided
00018  * you this software, covering your right to use that party's intellectual
00019  * property rights.
00020  *
00021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
00022  * copy of the source code appearing in this file ("Covered Code") an
00023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
00024  * base code distributed originally by Intel ("Original Intel Code") to copy,
00025  * make derivatives, distribute, use and display any portion of the Covered
00026  * Code in any form, with the right to sublicense such rights; and
00027  *
00028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
00029  * license (with the right to sublicense), under only those claims of Intel
00030  * patents that are infringed by the Original Intel Code, to make, use, sell,
00031  * offer to sell, and import the Covered Code and derivative works thereof
00032  * solely to the minimum extent necessary to exercise the above copyright
00033  * license, and in no event shall the patent license extend to any additions
00034  * to or modifications of the Original Intel Code.  No other license or right
00035  * is granted directly or by implication, estoppel or otherwise;
00036  *
00037  * The above copyright and patent license is granted only if the following
00038  * conditions are met:
00039  *
00040  * 3. Conditions
00041  *
00042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
00043  * Redistribution of source code of any substantial portion of the Covered
00044  * Code or modification with rights to further distribute source must include
00045  * the above Copyright Notice, the above License, this list of Conditions,
00046  * and the following Disclaimer and Export Compliance provision.  In addition,
00047  * Licensee must cause all Covered Code to which Licensee contributes to
00048  * contain a file documenting the changes Licensee made to create that Covered
00049  * Code and the date of any change.  Licensee must include in that file the
00050  * documentation of any changes made by any predecessor Licensee.  Licensee
00051  * must include a prominent statement that the modification is derived,
00052  * directly or indirectly, from Original Intel Code.
00053  *
00054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
00055  * Redistribution of source code of any substantial portion of the Covered
00056  * Code or modification without rights to further distribute source must
00057  * include the following Disclaimer and Export Compliance provision in the
00058  * documentation and/or other materials provided with distribution.  In
00059  * addition, Licensee may not authorize further sublicense of source of any
00060  * portion of the Covered Code, and must include terms to the effect that the
00061  * license from Licensee to its licensee is limited to the intellectual
00062  * property embodied in the software Licensee provides to its licensee, and
00063  * not to intellectual property embodied in modifications its licensee may
00064  * make.
00065  *
00066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
00067  * substantial portion of the Covered Code or modification must reproduce the
00068  * above Copyright Notice, and the following Disclaimer and Export Compliance
00069  * provision in the documentation and/or other materials provided with the
00070  * distribution.
00071  *
00072  * 3.4. Intel retains all right, title, and interest in and to the Original
00073  * Intel Code.
00074  *
00075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
00076  * Intel shall be used in advertising or otherwise to promote the sale, use or
00077  * other dealings in products derived from or relating to the Covered Code
00078  * without prior written authorization from Intel.
00079  *
00080  * 4. Disclaimer and Export Compliance
00081  *
00082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
00083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
00084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
00085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
00086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
00087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
00088  * PARTICULAR PURPOSE.
00089  *
00090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
00091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
00092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
00093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
00094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
00095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
00096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
00097  * LIMITED REMEDY.
00098  *
00099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
00100  * software or system incorporating such software without first obtaining any
00101  * required license or other approval from the U. S. Department of Commerce or
00102  * any other agency or department of the United States Government.  In the
00103  * event Licensee exports any such software from the United States or
00104  * re-exports any such software from a foreign destination, Licensee shall
00105  * ensure that the distribution and export/re-export of the software is in
00106  * compliance with all laws, regulations, orders, or other restrictions of the
00107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
00108  * any of its subsidiaries will export/re-export any technical data, process,
00109  * software, or service, directly or indirectly, to any country for which the
00110  * United States government or any agency thereof requires an export license,
00111  * other governmental approval, or letter of assurance, without first obtaining
00112  * such license, approval or letter.
00113  *
00114  *****************************************************************************/
00115 
00116 #include "acpi.h"
00117 #include "accommon.h"
00118 #include "acevents.h"
00119 #include "acinterp.h"
00120 
00121 #define _COMPONENT          ACPI_EVENTS
00122         ACPI_MODULE_NAME    ("evglock")
00123 
00124 
00125 /* Local prototypes */
00126 
00127 static UINT32
00128 AcpiEvGlobalLockHandler (
00129     void                    *Context);
00130 
00131 
00132 /*******************************************************************************
00133  *
00134  * FUNCTION:    AcpiEvInitGlobalLockHandler
00135  *
00136  * PARAMETERS:  None
00137  *
00138  * RETURN:      Status
00139  *
00140  * DESCRIPTION: Install a handler for the global lock release event
00141  *
00142  ******************************************************************************/
00143 
00144 ACPI_STATUS
00145 AcpiEvInitGlobalLockHandler (
00146     void)
00147 {
00148     ACPI_STATUS             Status;
00149 
00150 
00151     ACPI_FUNCTION_TRACE (EvInitGlobalLockHandler);
00152 
00153 
00154     /* Attempt installation of the global lock handler */
00155 
00156     Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL,
00157                 AcpiEvGlobalLockHandler, NULL);
00158 
00159     /*
00160      * If the global lock does not exist on this platform, the attempt to
00161      * enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick).
00162      * Map to AE_OK, but mark global lock as not present. Any attempt to
00163      * actually use the global lock will be flagged with an error.
00164      */
00165     AcpiGbl_GlobalLockPresent = FALSE;
00166     if (Status == AE_NO_HARDWARE_RESPONSE)
00167     {
00168         ACPI_ERROR ((AE_INFO,
00169             "No response from Global Lock hardware, disabling lock"));
00170 
00171         return_ACPI_STATUS (AE_OK);
00172     }
00173 
00174     Status = AcpiOsCreateLock (&AcpiGbl_GlobalLockPendingLock);
00175     if (ACPI_FAILURE (Status))
00176     {
00177         return_ACPI_STATUS (Status);
00178     }
00179 
00180     AcpiGbl_GlobalLockPending = FALSE;
00181     AcpiGbl_GlobalLockPresent = TRUE;
00182     return_ACPI_STATUS (Status);
00183 }
00184 
00185 
00186 /*******************************************************************************
00187  *
00188  * FUNCTION:    AcpiEvRemoveGlobalLockHandler
00189  *
00190  * PARAMETERS:  None
00191  *
00192  * RETURN:      Status
00193  *
00194  * DESCRIPTION: Remove the handler for the Global Lock
00195  *
00196  ******************************************************************************/
00197 
00198 ACPI_STATUS
00199 AcpiEvRemoveGlobalLockHandler (
00200     void)
00201 {
00202     ACPI_STATUS             Status;
00203 
00204 
00205     ACPI_FUNCTION_TRACE (EvRemoveGlobalLockHandler);
00206 
00207     AcpiGbl_GlobalLockPresent = FALSE;
00208     Status = AcpiRemoveFixedEventHandler (ACPI_EVENT_GLOBAL,
00209                 AcpiEvGlobalLockHandler);
00210 
00211     return_ACPI_STATUS (Status);
00212 }
00213 
00214 
00215 /*******************************************************************************
00216  *
00217  * FUNCTION:    AcpiEvGlobalLockHandler
00218  *
00219  * PARAMETERS:  Context         - From thread interface, not used
00220  *
00221  * RETURN:      ACPI_INTERRUPT_HANDLED
00222  *
00223  * DESCRIPTION: Invoked directly from the SCI handler when a global lock
00224  *              release interrupt occurs. If there is actually a pending
00225  *              request for the lock, signal the waiting thread.
00226  *
00227  ******************************************************************************/
00228 
00229 static UINT32
00230 AcpiEvGlobalLockHandler (
00231     void                    *Context)
00232 {
00233     ACPI_STATUS             Status;
00234     ACPI_CPU_FLAGS          Flags;
00235 
00236 
00237     Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
00238 
00239     /*
00240      * If a request for the global lock is not actually pending,
00241      * we are done. This handles "spurious" global lock interrupts
00242      * which are possible (and have been seen) with bad BIOSs.
00243      */
00244     if (!AcpiGbl_GlobalLockPending)
00245     {
00246         goto CleanupAndExit;
00247     }
00248 
00249     /*
00250      * Send a unit to the global lock semaphore. The actual acquisition
00251      * of the global lock will be performed by the waiting thread.
00252      */
00253     Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore, 1);
00254     if (ACPI_FAILURE (Status))
00255     {
00256         ACPI_ERROR ((AE_INFO, "Could not signal Global Lock semaphore"));
00257     }
00258 
00259     AcpiGbl_GlobalLockPending = FALSE;
00260 
00261 
00262 CleanupAndExit:
00263 
00264     AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
00265     return (ACPI_INTERRUPT_HANDLED);
00266 }
00267 
00268 
00269 /******************************************************************************
00270  *
00271  * FUNCTION:    AcpiEvAcquireGlobalLock
00272  *
00273  * PARAMETERS:  Timeout         - Max time to wait for the lock, in millisec.
00274  *
00275  * RETURN:      Status
00276  *
00277  * DESCRIPTION: Attempt to gain ownership of the Global Lock.
00278  *
00279  * MUTEX:       Interpreter must be locked
00280  *
00281  * Note: The original implementation allowed multiple threads to "acquire" the
00282  * Global Lock, and the OS would hold the lock until the last thread had
00283  * released it. However, this could potentially starve the BIOS out of the
00284  * lock, especially in the case where there is a tight handshake between the
00285  * Embedded Controller driver and the BIOS. Therefore, this implementation
00286  * allows only one thread to acquire the HW Global Lock at a time, and makes
00287  * the global lock appear as a standard mutex on the OS side.
00288  *
00289  *****************************************************************************/
00290 
00291 ACPI_STATUS
00292 AcpiEvAcquireGlobalLock (
00293     UINT16                  Timeout)
00294 {
00295     ACPI_CPU_FLAGS          Flags;
00296     ACPI_STATUS             Status;
00297     BOOLEAN                 Acquired = FALSE;
00298 
00299 
00300     ACPI_FUNCTION_TRACE (EvAcquireGlobalLock);
00301 
00302 
00303     /*
00304      * Only one thread can acquire the GL at a time, the GlobalLockMutex
00305      * enforces this. This interface releases the interpreter if we must wait.
00306      */
00307     Status = AcpiExSystemWaitMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex,
00308                 Timeout);
00309     if (ACPI_FAILURE (Status))
00310     {
00311         return_ACPI_STATUS (Status);
00312     }
00313 
00314     /*
00315      * Update the global lock handle and check for wraparound. The handle is
00316      * only used for the external global lock interfaces, but it is updated
00317      * here to properly handle the case where a single thread may acquire the
00318      * lock via both the AML and the AcpiAcquireGlobalLock interfaces. The
00319      * handle is therefore updated on the first acquire from a given thread
00320      * regardless of where the acquisition request originated.
00321      */
00322     AcpiGbl_GlobalLockHandle++;
00323     if (AcpiGbl_GlobalLockHandle == 0)
00324     {
00325         AcpiGbl_GlobalLockHandle = 1;
00326     }
00327 
00328     /*
00329      * Make sure that a global lock actually exists. If not, just
00330      * treat the lock as a standard mutex.
00331      */
00332     if (!AcpiGbl_GlobalLockPresent)
00333     {
00334         AcpiGbl_GlobalLockAcquired = TRUE;
00335         return_ACPI_STATUS (AE_OK);
00336     }
00337 
00338     Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
00339 
00340     do
00341     {
00342         /* Attempt to acquire the actual hardware lock */
00343 
00344         ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_FACS, Acquired);
00345         if (Acquired)
00346         {
00347             AcpiGbl_GlobalLockAcquired = TRUE;
00348             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
00349                 "Acquired hardware Global Lock\n"));
00350             break;
00351         }
00352 
00353         /*
00354          * Did not get the lock. The pending bit was set above, and
00355          * we must now wait until we receive the global lock
00356          * released interrupt.
00357          */
00358         AcpiGbl_GlobalLockPending = TRUE;
00359         AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
00360 
00361         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
00362             "Waiting for hardware Global Lock\n"));
00363 
00364         /*
00365          * Wait for handshake with the global lock interrupt handler.
00366          * This interface releases the interpreter if we must wait.
00367          */
00368         Status = AcpiExSystemWaitSemaphore (AcpiGbl_GlobalLockSemaphore,
00369                     ACPI_WAIT_FOREVER);
00370 
00371         Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
00372 
00373     } while (ACPI_SUCCESS (Status));
00374 
00375     AcpiGbl_GlobalLockPending = FALSE;
00376     AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
00377 
00378     return_ACPI_STATUS (Status);
00379 }
00380 
00381 
00382 /*******************************************************************************
00383  *
00384  * FUNCTION:    AcpiEvReleaseGlobalLock
00385  *
00386  * PARAMETERS:  None
00387  *
00388  * RETURN:      Status
00389  *
00390  * DESCRIPTION: Releases ownership of the Global Lock.
00391  *
00392  ******************************************************************************/
00393 
00394 ACPI_STATUS
00395 AcpiEvReleaseGlobalLock (
00396     void)
00397 {
00398     BOOLEAN                 Pending = FALSE;
00399     ACPI_STATUS             Status = AE_OK;
00400 
00401 
00402     ACPI_FUNCTION_TRACE (EvReleaseGlobalLock);
00403 
00404 
00405     /* Lock must be already acquired */
00406 
00407     if (!AcpiGbl_GlobalLockAcquired)
00408     {
00409         ACPI_WARNING ((AE_INFO,
00410             "Cannot release the ACPI Global Lock, it has not been acquired"));
00411         return_ACPI_STATUS (AE_NOT_ACQUIRED);
00412     }
00413 
00414     if (AcpiGbl_GlobalLockPresent)
00415     {
00416         /* Allow any thread to release the lock */
00417 
00418         ACPI_RELEASE_GLOBAL_LOCK (AcpiGbl_FACS, Pending);
00419 
00420         /*
00421          * If the pending bit was set, we must write GBL_RLS to the control
00422          * register
00423          */
00424         if (Pending)
00425         {
00426             Status = AcpiWriteBitRegister (
00427                         ACPI_BITREG_GLOBAL_LOCK_RELEASE, ACPI_ENABLE_EVENT);
00428         }
00429 
00430         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Released hardware Global Lock\n"));
00431     }
00432 
00433     AcpiGbl_GlobalLockAcquired = FALSE;
00434 
00435     /* Release the local GL mutex */
00436 
00437     AcpiOsReleaseMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex);
00438     return_ACPI_STATUS (Status);
00439 }

Generated on Sat May 26 2012 04:25:45 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.