Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenevgpeutil.c
Go to the documentation of this file.
00001 /****************************************************************************** 00002 * 00003 * Module Name: evgpeutil - GPE utilities 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 00117 #include "acpi.h" 00118 #include "accommon.h" 00119 #include "acevents.h" 00120 00121 #define _COMPONENT ACPI_EVENTS 00122 ACPI_MODULE_NAME ("evgpeutil") 00123 00124 00125 /******************************************************************************* 00126 * 00127 * FUNCTION: AcpiEvWalkGpeList 00128 * 00129 * PARAMETERS: GpeWalkCallback - Routine called for each GPE block 00130 * Context - Value passed to callback 00131 * 00132 * RETURN: Status 00133 * 00134 * DESCRIPTION: Walk the GPE lists. 00135 * 00136 ******************************************************************************/ 00137 00138 ACPI_STATUS 00139 AcpiEvWalkGpeList ( 00140 ACPI_GPE_CALLBACK GpeWalkCallback, 00141 void *Context) 00142 { 00143 ACPI_GPE_BLOCK_INFO *GpeBlock; 00144 ACPI_GPE_XRUPT_INFO *GpeXruptInfo; 00145 ACPI_STATUS Status = AE_OK; 00146 ACPI_CPU_FLAGS Flags; 00147 00148 00149 ACPI_FUNCTION_TRACE (EvWalkGpeList); 00150 00151 00152 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock); 00153 00154 /* Walk the interrupt level descriptor list */ 00155 00156 GpeXruptInfo = AcpiGbl_GpeXruptListHead; 00157 while (GpeXruptInfo) 00158 { 00159 /* Walk all Gpe Blocks attached to this interrupt level */ 00160 00161 GpeBlock = GpeXruptInfo->GpeBlockListHead; 00162 while (GpeBlock) 00163 { 00164 /* One callback per GPE block */ 00165 00166 Status = GpeWalkCallback (GpeXruptInfo, GpeBlock, Context); 00167 if (ACPI_FAILURE (Status)) 00168 { 00169 if (Status == AE_CTRL_END) /* Callback abort */ 00170 { 00171 Status = AE_OK; 00172 } 00173 goto UnlockAndExit; 00174 } 00175 00176 GpeBlock = GpeBlock->Next; 00177 } 00178 00179 GpeXruptInfo = GpeXruptInfo->Next; 00180 } 00181 00182 UnlockAndExit: 00183 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags); 00184 return_ACPI_STATUS (Status); 00185 } 00186 00187 00188 /******************************************************************************* 00189 * 00190 * FUNCTION: AcpiEvValidGpeEvent 00191 * 00192 * PARAMETERS: GpeEventInfo - Info for this GPE 00193 * 00194 * RETURN: TRUE if the GpeEvent is valid 00195 * 00196 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL. 00197 * Should be called only when the GPE lists are semaphore locked 00198 * and not subject to change. 00199 * 00200 ******************************************************************************/ 00201 00202 BOOLEAN 00203 AcpiEvValidGpeEvent ( 00204 ACPI_GPE_EVENT_INFO *GpeEventInfo) 00205 { 00206 ACPI_GPE_XRUPT_INFO *GpeXruptBlock; 00207 ACPI_GPE_BLOCK_INFO *GpeBlock; 00208 00209 00210 ACPI_FUNCTION_ENTRY (); 00211 00212 00213 /* No need for spin lock since we are not changing any list elements */ 00214 00215 /* Walk the GPE interrupt levels */ 00216 00217 GpeXruptBlock = AcpiGbl_GpeXruptListHead; 00218 while (GpeXruptBlock) 00219 { 00220 GpeBlock = GpeXruptBlock->GpeBlockListHead; 00221 00222 /* Walk the GPE blocks on this interrupt level */ 00223 00224 while (GpeBlock) 00225 { 00226 if ((&GpeBlock->EventInfo[0] <= GpeEventInfo) && 00227 (&GpeBlock->EventInfo[GpeBlock->GpeCount] > GpeEventInfo)) 00228 { 00229 return (TRUE); 00230 } 00231 00232 GpeBlock = GpeBlock->Next; 00233 } 00234 00235 GpeXruptBlock = GpeXruptBlock->Next; 00236 } 00237 00238 return (FALSE); 00239 } 00240 00241 00242 /******************************************************************************* 00243 * 00244 * FUNCTION: AcpiEvGetGpeDevice 00245 * 00246 * PARAMETERS: GPE_WALK_CALLBACK 00247 * 00248 * RETURN: Status 00249 * 00250 * DESCRIPTION: Matches the input GPE index (0-CurrentGpeCount) with a GPE 00251 * block device. NULL if the GPE is one of the FADT-defined GPEs. 00252 * 00253 ******************************************************************************/ 00254 00255 ACPI_STATUS 00256 AcpiEvGetGpeDevice ( 00257 ACPI_GPE_XRUPT_INFO *GpeXruptInfo, 00258 ACPI_GPE_BLOCK_INFO *GpeBlock, 00259 void *Context) 00260 { 00261 ACPI_GPE_DEVICE_INFO *Info = Context; 00262 00263 00264 /* Increment Index by the number of GPEs in this block */ 00265 00266 Info->NextBlockBaseIndex += GpeBlock->GpeCount; 00267 00268 if (Info->Index < Info->NextBlockBaseIndex) 00269 { 00270 /* 00271 * The GPE index is within this block, get the node. Leave the node 00272 * NULL for the FADT-defined GPEs 00273 */ 00274 if ((GpeBlock->Node)->Type == ACPI_TYPE_DEVICE) 00275 { 00276 Info->GpeDevice = GpeBlock->Node; 00277 } 00278 00279 Info->Status = AE_OK; 00280 return (AE_CTRL_END); 00281 } 00282 00283 return (AE_OK); 00284 } 00285 00286 00287 /******************************************************************************* 00288 * 00289 * FUNCTION: AcpiEvGetGpeXruptBlock 00290 * 00291 * PARAMETERS: InterruptNumber - Interrupt for a GPE block 00292 * 00293 * RETURN: A GPE interrupt block 00294 * 00295 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt 00296 * block per unique interrupt level used for GPEs. Should be 00297 * called only when the GPE lists are semaphore locked and not 00298 * subject to change. 00299 * 00300 ******************************************************************************/ 00301 00302 ACPI_GPE_XRUPT_INFO * 00303 AcpiEvGetGpeXruptBlock ( 00304 UINT32 InterruptNumber) 00305 { 00306 ACPI_GPE_XRUPT_INFO *NextGpeXrupt; 00307 ACPI_GPE_XRUPT_INFO *GpeXrupt; 00308 ACPI_STATUS Status; 00309 ACPI_CPU_FLAGS Flags; 00310 00311 00312 ACPI_FUNCTION_TRACE (EvGetGpeXruptBlock); 00313 00314 00315 /* No need for lock since we are not changing any list elements here */ 00316 00317 NextGpeXrupt = AcpiGbl_GpeXruptListHead; 00318 while (NextGpeXrupt) 00319 { 00320 if (NextGpeXrupt->InterruptNumber == InterruptNumber) 00321 { 00322 return_PTR (NextGpeXrupt); 00323 } 00324 00325 NextGpeXrupt = NextGpeXrupt->Next; 00326 } 00327 00328 /* Not found, must allocate a new xrupt descriptor */ 00329 00330 GpeXrupt = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_XRUPT_INFO)); 00331 if (!GpeXrupt) 00332 { 00333 return_PTR (NULL); 00334 } 00335 00336 GpeXrupt->InterruptNumber = InterruptNumber; 00337 00338 /* Install new interrupt descriptor with spin lock */ 00339 00340 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock); 00341 if (AcpiGbl_GpeXruptListHead) 00342 { 00343 NextGpeXrupt = AcpiGbl_GpeXruptListHead; 00344 while (NextGpeXrupt->Next) 00345 { 00346 NextGpeXrupt = NextGpeXrupt->Next; 00347 } 00348 00349 NextGpeXrupt->Next = GpeXrupt; 00350 GpeXrupt->Previous = NextGpeXrupt; 00351 } 00352 else 00353 { 00354 AcpiGbl_GpeXruptListHead = GpeXrupt; 00355 } 00356 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags); 00357 00358 /* Install new interrupt handler if not SCI_INT */ 00359 00360 if (InterruptNumber != AcpiGbl_FADT.SciInterrupt) 00361 { 00362 Status = AcpiOsInstallInterruptHandler (InterruptNumber, 00363 AcpiEvGpeXruptHandler, GpeXrupt); 00364 if (ACPI_FAILURE (Status)) 00365 { 00366 ACPI_ERROR ((AE_INFO, 00367 "Could not install GPE interrupt handler at level 0x%X", 00368 InterruptNumber)); 00369 return_PTR (NULL); 00370 } 00371 } 00372 00373 return_PTR (GpeXrupt); 00374 } 00375 00376 00377 /******************************************************************************* 00378 * 00379 * FUNCTION: AcpiEvDeleteGpeXrupt 00380 * 00381 * PARAMETERS: GpeXrupt - A GPE interrupt info block 00382 * 00383 * RETURN: Status 00384 * 00385 * DESCRIPTION: Remove and free a GpeXrupt block. Remove an associated 00386 * interrupt handler if not the SCI interrupt. 00387 * 00388 ******************************************************************************/ 00389 00390 ACPI_STATUS 00391 AcpiEvDeleteGpeXrupt ( 00392 ACPI_GPE_XRUPT_INFO *GpeXrupt) 00393 { 00394 ACPI_STATUS Status; 00395 ACPI_CPU_FLAGS Flags; 00396 00397 00398 ACPI_FUNCTION_TRACE (EvDeleteGpeXrupt); 00399 00400 00401 /* We never want to remove the SCI interrupt handler */ 00402 00403 if (GpeXrupt->InterruptNumber == AcpiGbl_FADT.SciInterrupt) 00404 { 00405 GpeXrupt->GpeBlockListHead = NULL; 00406 return_ACPI_STATUS (AE_OK); 00407 } 00408 00409 /* Disable this interrupt */ 00410 00411 Status = AcpiOsRemoveInterruptHandler ( 00412 GpeXrupt->InterruptNumber, AcpiEvGpeXruptHandler); 00413 if (ACPI_FAILURE (Status)) 00414 { 00415 return_ACPI_STATUS (Status); 00416 } 00417 00418 /* Unlink the interrupt block with lock */ 00419 00420 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock); 00421 if (GpeXrupt->Previous) 00422 { 00423 GpeXrupt->Previous->Next = GpeXrupt->Next; 00424 } 00425 else 00426 { 00427 /* No previous, update list head */ 00428 00429 AcpiGbl_GpeXruptListHead = GpeXrupt->Next; 00430 } 00431 00432 if (GpeXrupt->Next) 00433 { 00434 GpeXrupt->Next->Previous = GpeXrupt->Previous; 00435 } 00436 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags); 00437 00438 /* Free the block */ 00439 00440 ACPI_FREE (GpeXrupt); 00441 return_ACPI_STATUS (AE_OK); 00442 } 00443 00444 00445 /******************************************************************************* 00446 * 00447 * FUNCTION: AcpiEvDeleteGpeHandlers 00448 * 00449 * PARAMETERS: GpeXruptInfo - GPE Interrupt info 00450 * GpeBlock - Gpe Block info 00451 * 00452 * RETURN: Status 00453 * 00454 * DESCRIPTION: Delete all Handler objects found in the GPE data structs. 00455 * Used only prior to termination. 00456 * 00457 ******************************************************************************/ 00458 00459 ACPI_STATUS 00460 AcpiEvDeleteGpeHandlers ( 00461 ACPI_GPE_XRUPT_INFO *GpeXruptInfo, 00462 ACPI_GPE_BLOCK_INFO *GpeBlock, 00463 void *Context) 00464 { 00465 ACPI_GPE_EVENT_INFO *GpeEventInfo; 00466 UINT32 i; 00467 UINT32 j; 00468 00469 00470 ACPI_FUNCTION_TRACE (EvDeleteGpeHandlers); 00471 00472 00473 /* Examine each GPE Register within the block */ 00474 00475 for (i = 0; i < GpeBlock->RegisterCount; i++) 00476 { 00477 /* Now look at the individual GPEs in this byte register */ 00478 00479 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) 00480 { 00481 GpeEventInfo = &GpeBlock->EventInfo[((ACPI_SIZE) i * 00482 ACPI_GPE_REGISTER_WIDTH) + j]; 00483 00484 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) == 00485 ACPI_GPE_DISPATCH_HANDLER) 00486 { 00487 ACPI_FREE (GpeEventInfo->Dispatch.Handler); 00488 GpeEventInfo->Dispatch.Handler = NULL; 00489 GpeEventInfo->Flags &= ~ACPI_GPE_DISPATCH_MASK; 00490 } 00491 } 00492 } 00493 00494 return_ACPI_STATUS (AE_OK); 00495 } 00496 Generated on Sat May 26 2012 04:25:45 for ReactOS by
1.7.6.1
|