static ACPI_STATUS AeExceptionHandler ( ACPI_STATUS AmlStatus, ACPI_NAME Name, UINT16 Opcode, UINT32 AmlOffset, void *Context) { ACPI_STATUS NewAmlStatus = AmlStatus; ACPI_STATUS Status; ACPI_BUFFER ReturnObj; ACPI_OBJECT_LIST ArgList; ACPI_OBJECT Arg[3]; const char *Exception; Exception = AcpiFormatException (AmlStatus); AcpiOsPrintf ("[AcpiExec] Exception %s during execution ", Exception); if (Name) { AcpiOsPrintf ("of method [%4.4s]", (char *) &Name); } else { AcpiOsPrintf ("at module level (table load)"); } AcpiOsPrintf (" Opcode [%s] @%X\n", AcpiPsGetOpcodeName (Opcode), AmlOffset); /* * Invoke the _ERR method if present * * Setup parameter object */ ArgList.Count = 3; ArgList.Pointer = Arg; Arg[0].Type = ACPI_TYPE_INTEGER; Arg[0].Integer.Value = AmlStatus; Arg[1].Type = ACPI_TYPE_STRING; Arg[1].String.Pointer = ACPI_CAST_PTR (char, Exception); Arg[1].String.Length = ACPI_STRLEN (Exception); Arg[2].Type = ACPI_TYPE_INTEGER; Arg[2].Integer.Value = AcpiOsGetThreadId(); /* Setup return buffer */ ReturnObj.Pointer = NULL; ReturnObj.Length = ACPI_ALLOCATE_BUFFER; Status = AcpiEvaluateObject (NULL, "\\_ERR", &ArgList, &ReturnObj); if (ACPI_SUCCESS (Status)) { if (ReturnObj.Pointer) { /* Override original status */ NewAmlStatus = (ACPI_STATUS) ((ACPI_OBJECT *) ReturnObj.Pointer)->Integer.Value; /* Free a buffer created via ACPI_ALLOCATE_BUFFER */ AcpiOsFree (ReturnObj.Pointer); } } else if (Status != AE_NOT_FOUND) { AcpiOsPrintf ("[AcpiExec] Could not execute _ERR method, %s\n", AcpiFormatException (Status)); } /* Global override */ if (AcpiGbl_IgnoreErrors) { NewAmlStatus = AE_OK; } if (NewAmlStatus != AmlStatus) { AcpiOsPrintf ("[AcpiExec] Exception override, new status %s\n", AcpiFormatException (NewAmlStatus)); } return (NewAmlStatus); }
static void ACPI_SYSTEM_XFACE AcpiDbMethodThread ( void *Context) { ACPI_STATUS Status; ACPI_DB_METHOD_INFO *Info = Context; ACPI_DB_METHOD_INFO LocalInfo; UINT32 i; UINT8 Allow; ACPI_BUFFER ReturnObj; /* * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments. * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads * concurrently. * * Note: The arguments we are passing are used by the ASL test suite * (aslts). Do not change them without updating the tests. */ (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER); if (Info->InitArgs) { AcpiDbUint32ToHexString (Info->NumCreated, Info->IndexOfThreadStr); AcpiDbUint32ToHexString ((UINT32) AcpiOsGetThreadId (), Info->IdOfThreadStr); } if (Info->Threads && (Info->NumCreated < Info->NumThreads)) { Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId(); } LocalInfo = *Info; LocalInfo.Args = LocalInfo.Arguments; LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr; LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr; LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr; LocalInfo.Arguments[3] = NULL; LocalInfo.Types = LocalInfo.ArgTypes; (void) AcpiOsSignalSemaphore (Info->InfoGate, 1); for (i = 0; i < Info->NumLoops; i++) { Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("%s During evaluation of %s at iteration %X\n", AcpiFormatException (Status), Info->Pathname, i); if (Status == AE_ABORT_METHOD) { break; } } #if 0 if ((i % 100) == 0) { AcpiOsPrintf ("%u loops, Thread 0x%x\n", i, AcpiOsGetThreadId ()); } if (ReturnObj.Length) { AcpiOsPrintf ("Evaluation of %s returned object %p Buflen %X\n", Info->Pathname, ReturnObj.Pointer, (UINT32) ReturnObj.Length); AcpiDbDumpExternalObject (ReturnObj.Pointer, 1); } #endif } /* Signal our completion */ Allow = 0; (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate, 1, ACPI_WAIT_FOREVER); Info->NumCompleted++; if (Info->NumCompleted == Info->NumThreads) { /* Do signal for main thread once only */ Allow = 1; } (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1); if (Allow) { Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Could not signal debugger thread sync semaphore, %s\n", AcpiFormatException (Status)); } } }
void ACPI_INTERNAL_VAR_XFACE AcpiDebugPrint ( UINT32 RequestedDebugLevel, UINT32 LineNumber, const char *FunctionName, const char *ModuleName, UINT32 ComponentId, const char *Format, ...) { ACPI_THREAD_ID ThreadId; va_list args; /* Check if debug output enabled */ if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId)) { return; } /* * Thread tracking and context switch notification */ ThreadId = AcpiOsGetThreadId (); if (ThreadId != AcpiGbl_PrevThreadId) { if (ACPI_LV_THREADS & AcpiDbgLevel) { AcpiOsPrintf ( "\n**** Context Switch from TID %u to TID %u ****\n\n", (UINT32) AcpiGbl_PrevThreadId, (UINT32) ThreadId); } AcpiGbl_PrevThreadId = ThreadId; AcpiGbl_NestingLevel = 0; } /* * Display the module name, current line number, thread ID (if requested), * current procedure nesting level, and the current procedure name */ AcpiOsPrintf ("%9s-%04ld ", ModuleName, LineNumber); #ifdef ACPI_APPLICATION /* * For AcpiExec/iASL only, emit the thread ID and nesting level. * Note: nesting level is really only useful during a single-thread * execution. Otherwise, multiple threads will keep resetting the * level. */ if (ACPI_LV_THREADS & AcpiDbgLevel) { AcpiOsPrintf ("[%u] ", (UINT32) ThreadId); } AcpiOsPrintf ("[%02ld] ", AcpiGbl_NestingLevel); #endif AcpiOsPrintf ("%-22.22s: ", AcpiUtTrimFunctionName (FunctionName)); va_start (args, Format); AcpiOsVprintf (Format, args); va_end (args); }
ACPI_STATUS AcpiOsWaitSemaphore(ACPI_HANDLE Handle, UINT32 Units, UINT16 Timeout) { #ifndef ACPI_NO_SEMAPHORES ACPI_STATUS result; struct acpi_semaphore *as = (struct acpi_semaphore *)Handle; int rv, tmo; struct timeval timeouttv, currenttv, timelefttv; AS_LOCK_DECL; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); if (as == NULL) return_ACPI_STATUS (AE_BAD_PARAMETER); if (cold) return_ACPI_STATUS (AE_OK); #if 0 if (as->as_units < Units && as->as_timeouts > 10) { kprintf("%s: semaphore %p too many timeouts, resetting\n", __func__, as); AS_LOCK(as); as->as_units = as->as_maxunits; if (as->as_pendings) as->as_resetting = 1; as->as_timeouts = 0; wakeup(as); AS_UNLOCK(as); return_ACPI_STATUS (AE_TIME); } if (as->as_resetting) return_ACPI_STATUS (AE_TIME); #endif /* a timeout of ACPI_WAIT_FOREVER means "forever" */ if (Timeout == ACPI_WAIT_FOREVER) { tmo = 0; timeouttv.tv_sec = ((0xffff/1000) + 1); /* cf. ACPI spec */ timeouttv.tv_usec = 0; } else { /* compute timeout using microseconds per tick */ tmo = (Timeout * 1000) / (1000000 / hz); if (tmo <= 0) tmo = 1; timeouttv.tv_sec = Timeout / 1000; timeouttv.tv_usec = (Timeout % 1000) * 1000; } /* calculate timeout value in timeval */ getmicrouptime(¤ttv); timevaladd(&timeouttv, ¤ttv); AS_LOCK(as); ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "get %d units from semaphore %p (has %d), timeout %d\n", Units, as, as->as_units, Timeout)); for (;;) { if (as->as_maxunits == ACPI_NO_UNIT_LIMIT) { result = AE_OK; break; } if (as->as_units >= Units) { as->as_units -= Units; result = AE_OK; break; } /* limit number of pending treads */ if (as->as_pendings >= ACPI_SEMAPHORES_MAX_PENDING) { result = AE_TIME; break; } /* if timeout values of zero is specified, return immediately */ if (Timeout == 0) { result = AE_TIME; break; } ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "semaphore blocked, calling ssleep(%p, %p, %d, \"acsem\", %d)\n", as, &as->as_spin, PCATCH, tmo)); as->as_pendings++; if (acpi_semaphore_debug) { kprintf("%s: Sleep %jd, pending %jd, semaphore %p, thread %jd\n", __func__, (intmax_t)Timeout, (intmax_t)as->as_pendings, as, (intmax_t)AcpiOsGetThreadId()); } rv = ssleep(as, &as->as_spin, PCATCH, "acsem", tmo); as->as_pendings--; #if 0 if (as->as_resetting) { /* semaphore reset, return immediately */ if (as->as_pendings == 0) { as->as_resetting = 0; } result = AE_TIME; break; } #endif ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "ssleep(%d) returned %d\n", tmo, rv)); if (rv == EWOULDBLOCK) { result = AE_TIME; break; } /* check if we already awaited enough */ timelefttv = timeouttv; getmicrouptime(¤ttv); timevalsub(&timelefttv, ¤ttv); if (timelefttv.tv_sec < 0) { ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "await semaphore %p timeout\n", as)); result = AE_TIME; break; } /* adjust timeout for the next sleep */ tmo = (timelefttv.tv_sec * 1000000 + timelefttv.tv_usec) / (1000000 / hz); if (tmo <= 0) tmo = 1; if (acpi_semaphore_debug) { kprintf("%s: Wakeup timeleft(%ju, %ju), tmo %ju, sem %p, thread %jd\n", __func__, (intmax_t)timelefttv.tv_sec, (intmax_t)timelefttv.tv_usec, (intmax_t)tmo, as, (intmax_t)AcpiOsGetThreadId()); } } if (acpi_semaphore_debug) { if (result == AE_TIME && Timeout > 0) { kprintf("%s: Timeout %d, pending %d, semaphore %p\n", __func__, Timeout, as->as_pendings, as); } if (ACPI_SUCCESS(result) && (as->as_timeouts > 0 || as->as_pendings > 0)) { kprintf("%s: Acquire %d, units %d, pending %d, sem %p, thread %jd\n", __func__, Units, as->as_units, as->as_pendings, as, (intmax_t)AcpiOsGetThreadId()); } } if (result == AE_TIME) as->as_timeouts++; else as->as_timeouts = 0; AS_UNLOCK(as); return_ACPI_STATUS (result); #else return_ACPI_STATUS (AE_OK); #endif /* !ACPI_NO_SEMAPHORES */ }
ACPI_STATUS AcpiUtReleaseMutex ( ACPI_MUTEX_HANDLE MutexId) { ACPI_THREAD_ID ThisThreadId; ACPI_FUNCTION_NAME (UtReleaseMutex); ThisThreadId = AcpiOsGetThreadId (); ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %u releasing Mutex [%s]\n", (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId))); if (MutexId > ACPI_MAX_MUTEX) { return (AE_BAD_PARAMETER); } /* * Mutex must be acquired in order to release it! */ if (AcpiGbl_MutexInfo[MutexId].ThreadId == ACPI_MUTEX_NOT_ACQUIRED) { ACPI_ERROR ((AE_INFO, "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 (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId) { if (i == MutexId) { continue; } ACPI_ERROR ((AE_INFO, "Invalid release order: owns [%s], releasing [%s]", AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId))); return (AE_RELEASE_DEADLOCK); } } } #endif /* Mark unlocked FIRST */ AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED; AcpiOsReleaseMutex (AcpiGbl_MutexInfo[MutexId].Mutex); return (AE_OK); }
ACPI_STATUS AcpiDsBeginMethodExecution ( ACPI_NAMESPACE_NODE *MethodNode, ACPI_OPERAND_OBJECT *ObjDesc, ACPI_WALK_STATE *WalkState) { ACPI_STATUS Status = AE_OK; ACPI_FUNCTION_TRACE_PTR (DsBeginMethodExecution, MethodNode); if (!MethodNode) { return_ACPI_STATUS (AE_NULL_ENTRY); } AcpiExStartTraceMethod (MethodNode, ObjDesc, WalkState); /* Prevent wraparound of thread count */ if (ObjDesc->Method.ThreadCount == ACPI_UINT8_MAX) { ACPI_ERROR ((AE_INFO, "Method reached maximum reentrancy limit (255)")); return_ACPI_STATUS (AE_AML_METHOD_LIMIT); } /* * If this method is serialized, we need to acquire the method mutex. */ if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED) { /* * Create a mutex for the method if it is defined to be Serialized * and a mutex has not already been created. We defer the mutex creation * until a method is actually executed, to minimize the object count */ if (!ObjDesc->Method.Mutex) { Status = AcpiDsCreateMethodMutex (ObjDesc); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } /* * The CurrentSyncLevel (per-thread) must be less than or equal to * the sync level of the method. This mechanism provides some * deadlock prevention. * * If the method was auto-serialized, we just ignore the sync level * mechanism, because auto-serialization of methods can interfere * with ASL code that actually uses sync levels. * * Top-level method invocation has no walk state at this point */ if (WalkState && (!(ObjDesc->Method.InfoFlags & ACPI_METHOD_IGNORE_SYNC_LEVEL)) && (WalkState->Thread->CurrentSyncLevel > ObjDesc->Method.Mutex->Mutex.SyncLevel)) { ACPI_ERROR ((AE_INFO, "Cannot acquire Mutex for method [%4.4s]" ", current SyncLevel is too large (%u)", AcpiUtGetNodeName (MethodNode), WalkState->Thread->CurrentSyncLevel)); return_ACPI_STATUS (AE_AML_MUTEX_ORDER); } /* * Obtain the method mutex if necessary. Do not acquire mutex for a * recursive call. */ if (!WalkState || !ObjDesc->Method.Mutex->Mutex.ThreadId || (WalkState->Thread->ThreadId != ObjDesc->Method.Mutex->Mutex.ThreadId)) { /* * Acquire the method mutex. This releases the interpreter if we * block (and reacquires it before it returns) */ Status = AcpiExSystemWaitMutex ( ObjDesc->Method.Mutex->Mutex.OsMutex, ACPI_WAIT_FOREVER); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Update the mutex and walk info and save the original SyncLevel */ if (WalkState) { ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel = WalkState->Thread->CurrentSyncLevel; ObjDesc->Method.Mutex->Mutex.ThreadId = WalkState->Thread->ThreadId; /* * Update the current SyncLevel only if this is not an auto- * serialized method. In the auto case, we have to ignore * the sync level for the method mutex (created for the * auto-serialization) because we have no idea of what the * sync level should be. Therefore, just ignore it. */ if (!(ObjDesc->Method.InfoFlags & ACPI_METHOD_IGNORE_SYNC_LEVEL)) { WalkState->Thread->CurrentSyncLevel = ObjDesc->Method.SyncLevel; } } else { ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel = ObjDesc->Method.Mutex->Mutex.SyncLevel; ObjDesc->Method.Mutex->Mutex.ThreadId = AcpiOsGetThreadId (); } } /* Always increase acquisition depth */ ObjDesc->Method.Mutex->Mutex.AcquisitionDepth++; } /* * Allocate an Owner ID for this method, only if this is the first thread * to begin concurrent execution. We only need one OwnerId, even if the * method is invoked recursively. */ if (!ObjDesc->Method.OwnerId) { Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId); if (ACPI_FAILURE (Status)) { goto Cleanup; } } /* * Increment the method parse tree thread count since it has been * reentered one more time (even if it is the same thread) */ ObjDesc->Method.ThreadCount++; AcpiMethodCount++; return_ACPI_STATUS (Status); Cleanup: /* On error, must release the method mutex (if present) */ if (ObjDesc->Method.Mutex) { AcpiOsReleaseMutex (ObjDesc->Method.Mutex->Mutex.OsMutex); } return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiUtAcquireMutex ( ACPI_MUTEX_HANDLE MutexId) { ACPI_STATUS Status; ACPI_THREAD_ID ThisThreadId; ACPI_FUNCTION_NAME (UtAcquireMutex); if (MutexId > ACPI_MAX_MUTEX) { return (AE_BAD_PARAMETER); } ThisThreadId = AcpiOsGetThreadId (); #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 (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId) { if (i == MutexId) { ACPI_ERROR ((AE_INFO, "Mutex [%s] already acquired by this thread [%u]", AcpiUtGetMutexName (MutexId), (UINT32) ThisThreadId)); return (AE_ALREADY_ACQUIRED); } ACPI_ERROR ((AE_INFO, "Invalid acquire order: Thread %u owns [%s], wants [%s]", (UINT32) ThisThreadId, AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId))); return (AE_ACQUIRE_DEADLOCK); } } } #endif ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %u attempting to acquire Mutex [%s]\n", (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId))); Status = AcpiOsAcquireMutex (AcpiGbl_MutexInfo[MutexId].Mutex, ACPI_WAIT_FOREVER); if (ACPI_SUCCESS (Status)) { ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %u acquired Mutex [%s]\n", (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId))); AcpiGbl_MutexInfo[MutexId].UseCount++; AcpiGbl_MutexInfo[MutexId].ThreadId = ThisThreadId; } else { ACPI_EXCEPTION ((AE_INFO, Status, "Thread %u could not acquire Mutex [0x%X]", (UINT32) ThisThreadId, MutexId)); } return (Status); }
ACPI_STATUS AcpiInitializeDebugger ( void) { ACPI_STATUS Status; ACPI_FUNCTION_TRACE (AcpiInitializeDebugger); /* Init globals */ AcpiGbl_DbBuffer = NULL; AcpiGbl_DbFilename = NULL; AcpiGbl_DbOutputToFile = FALSE; AcpiGbl_DbDebugLevel = ACPI_LV_VERBOSITY2; AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES; AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT; AcpiGbl_DbOpt_NoIniMethods = FALSE; AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE); if (!AcpiGbl_DbBuffer) { return_ACPI_STATUS (AE_NO_MEMORY); } memset (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE); /* Initial scope is the root */ AcpiGbl_DbScopeBuf [0] = AML_ROOT_PREFIX; AcpiGbl_DbScopeBuf [1] = 0; AcpiGbl_DbScopeNode = AcpiGbl_RootNode; /* Initialize user commands loop */ AcpiGbl_DbTerminateLoop = FALSE; /* * If configured for multi-thread support, the debug executor runs in * a separate thread so that the front end can be in another address * space, environment, or even another machine. */ if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED) { /* These were created with one unit, grab it */ Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete, ACPI_WAIT_FOREVER); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Could not get debugger mutex\n"); return_ACPI_STATUS (Status); } Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady, ACPI_WAIT_FOREVER); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Could not get debugger mutex\n"); return_ACPI_STATUS (Status); } /* Create the debug execution thread to execute commands */ AcpiGbl_DbThreadsTerminated = FALSE; Status = AcpiOsExecute (OSL_DEBUGGER_MAIN_THREAD, AcpiDbExecuteThread, NULL); if (ACPI_FAILURE (Status)) { ACPI_EXCEPTION ((AE_INFO, Status, "Could not start debugger thread")); AcpiGbl_DbThreadsTerminated = TRUE; return_ACPI_STATUS (Status); } } else { AcpiGbl_DbThreadId = AcpiOsGetThreadId (); } return_ACPI_STATUS (AE_OK); }
ACPI_STATUS AcpiDbSingleStep ( ACPI_WALK_STATE *WalkState, ACPI_PARSE_OBJECT *Op, UINT32 OpcodeClass) { ACPI_PARSE_OBJECT *Next; ACPI_STATUS Status = AE_OK; UINT32 OriginalDebugLevel; ACPI_PARSE_OBJECT *DisplayOp; ACPI_PARSE_OBJECT *ParentOp; UINT32 AmlOffset; ACPI_FUNCTION_ENTRY (); #ifndef ACPI_APPLICATION if (AcpiGbl_DbThreadId != AcpiOsGetThreadId ()) { return (AE_OK); } #endif /* Check the abort flag */ if (AcpiGbl_AbortMethod) { AcpiGbl_AbortMethod = FALSE; return (AE_ABORT_METHOD); } AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml, WalkState->ParserState.AmlStart); /* Check for single-step breakpoint */ if (WalkState->MethodBreakpoint && (WalkState->MethodBreakpoint <= AmlOffset)) { /* Check if the breakpoint has been reached or passed */ /* Hit the breakpoint, resume single step, reset breakpoint */ AcpiOsPrintf ("***Break*** at AML offset %X\n", AmlOffset); AcpiGbl_CmSingleStep = TRUE; AcpiGbl_StepToNextCall = FALSE; WalkState->MethodBreakpoint = 0; } /* Check for user breakpoint (Must be on exact Aml offset) */ else if (WalkState->UserBreakpoint && (WalkState->UserBreakpoint == AmlOffset)) { AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n", AmlOffset); AcpiGbl_CmSingleStep = TRUE; AcpiGbl_StepToNextCall = FALSE; WalkState->MethodBreakpoint = 0; } /* * Check if this is an opcode that we are interested in -- * namely, opcodes that have arguments */ if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP) { return (AE_OK); } switch (OpcodeClass) { case AML_CLASS_UNKNOWN: case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */ return (AE_OK); default: /* All other opcodes -- continue */ break; } /* * Under certain debug conditions, display this opcode and its operands */ if ((AcpiGbl_DbOutputToFile) || (AcpiGbl_CmSingleStep) || (AcpiDbgLevel & ACPI_LV_PARSE)) { if ((AcpiGbl_DbOutputToFile) || (AcpiDbgLevel & ACPI_LV_PARSE)) { AcpiOsPrintf ("\n[AmlDebug] Next AML Opcode to execute:\n"); } /* * Display this op (and only this op - zero out the NEXT field * temporarily, and disable parser trace output for the duration of * the display because we don't want the extraneous debug output) */ OriginalDebugLevel = AcpiDbgLevel; AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS); Next = Op->Common.Next; Op->Common.Next = NULL; DisplayOp = Op; ParentOp = Op->Common.Parent; if (ParentOp) { if ((WalkState->ControlState) && (WalkState->ControlState->Common.State == ACPI_CONTROL_PREDICATE_EXECUTING)) { /* * We are executing the predicate of an IF or WHILE statement * Search upwards for the containing IF or WHILE so that the * entire predicate can be displayed. */ while (ParentOp) { if ((ParentOp->Common.AmlOpcode == AML_IF_OP) || (ParentOp->Common.AmlOpcode == AML_WHILE_OP)) { DisplayOp = ParentOp; break; } ParentOp = ParentOp->Common.Parent; } } else { while (ParentOp) { if ((ParentOp->Common.AmlOpcode == AML_IF_OP) || (ParentOp->Common.AmlOpcode == AML_ELSE_OP) || (ParentOp->Common.AmlOpcode == AML_SCOPE_OP) || (ParentOp->Common.AmlOpcode == AML_METHOD_OP) || (ParentOp->Common.AmlOpcode == AML_WHILE_OP)) { break; } DisplayOp = ParentOp; ParentOp = ParentOp->Common.Parent; } } } /* Now we can display it */ #ifdef ACPI_DISASSEMBLER AcpiDmDisassemble (WalkState, DisplayOp, ACPI_UINT32_MAX); #endif if ((Op->Common.AmlOpcode == AML_IF_OP) || (Op->Common.AmlOpcode == AML_WHILE_OP)) { if (WalkState->ControlState->Common.Value) { AcpiOsPrintf ("Predicate = [True], IF block was executed\n"); } else { AcpiOsPrintf ("Predicate = [False], Skipping IF block\n"); } } else if (Op->Common.AmlOpcode == AML_ELSE_OP) { AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n"); } /* Restore everything */ Op->Common.Next = Next; AcpiOsPrintf ("\n"); if ((AcpiGbl_DbOutputToFile) || (AcpiDbgLevel & ACPI_LV_PARSE)) { AcpiOsPrintf ("\n"); } AcpiDbgLevel = OriginalDebugLevel; } /* If we are not single stepping, just continue executing the method */ if (!AcpiGbl_CmSingleStep) { return (AE_OK); } /* * If we are executing a step-to-call command, * Check if this is a method call. */ if (AcpiGbl_StepToNextCall) { if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP) { /* Not a method call, just keep executing */ return (AE_OK); } /* Found a method call, stop executing */ AcpiGbl_StepToNextCall = FALSE; } /* * If the next opcode is a method call, we will "step over" it * by default. */ if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP) { /* Force no more single stepping while executing called method */ AcpiGbl_CmSingleStep = FALSE; /* * Set the breakpoint on/before the call, it will stop execution * as soon as we return */ WalkState->MethodBreakpoint = 1; /* Must be non-zero! */ } Status = AcpiDbStartCommand (WalkState, Op); /* User commands complete, continue execution of the interrupted method */ return (Status); }
ACPI_STATUS AcpiUtReleaseMutex ( ACPI_MUTEX_HANDLE MutexId) { ACPI_STATUS Status; UINT32 i; UINT32 ThisThreadId; ACPI_FUNCTION_NAME ("UtReleaseMutex"); ThisThreadId = AcpiOsGetThreadId (); ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X releasing Mutex [%s]\n", ThisThreadId, AcpiUtGetMutexName (MutexId))); if (MutexId > MAX_MTX) { return (AE_BAD_PARAMETER); } /* * Mutex must be acquired in order to release it! */ if (AcpiGbl_AcpiMutexInfo[MutexId].OwnerId == ACPI_MUTEX_NOT_ACQUIRED) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Mutex [%s] is not acquired, cannot release\n", AcpiUtGetMutexName (MutexId))); return (AE_NOT_ACQUIRED); } /* * 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 < MAX_MTX; i++) { if (AcpiGbl_AcpiMutexInfo[i].OwnerId == ThisThreadId) { if (i == MutexId) { continue; } ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid release order: owns [%s], releasing [%s]\n", AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId))); return (AE_RELEASE_DEADLOCK); } } /* Mark unlocked FIRST */ AcpiGbl_AcpiMutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED; Status = AcpiOsSignalSemaphore (AcpiGbl_AcpiMutexInfo[MutexId].Mutex, 1); if (ACPI_FAILURE (Status)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not release Mutex [%s] %s\n", ThisThreadId, AcpiUtGetMutexName (MutexId), AcpiFormatException (Status))); } else { ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n", ThisThreadId, AcpiUtGetMutexName (MutexId))); } return (Status); }
ACPI_STATUS AcpiUtAcquireMutex ( ACPI_MUTEX_HANDLE MutexId) { ACPI_STATUS Status; UINT32 i; UINT32 ThisThreadId; ACPI_FUNCTION_NAME ("UtAcquireMutex"); if (MutexId > MAX_MTX) { return (AE_BAD_PARAMETER); } ThisThreadId = AcpiOsGetThreadId (); /* * 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 < MAX_MTX; i++) { if (AcpiGbl_AcpiMutexInfo[i].OwnerId == ThisThreadId) { if (i == MutexId) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Mutex [%s] already acquired by this thread [%X]\n", AcpiUtGetMutexName (MutexId), ThisThreadId)); return (AE_ALREADY_ACQUIRED); } ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid acquire order: Thread %X owns [%s], wants [%s]\n", ThisThreadId, AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId))); return (AE_ACQUIRE_DEADLOCK); } } ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X attempting to acquire Mutex [%s]\n", ThisThreadId, AcpiUtGetMutexName (MutexId))); Status = AcpiOsWaitSemaphore (AcpiGbl_AcpiMutexInfo[MutexId].Mutex, 1, ACPI_WAIT_FOREVER); if (ACPI_SUCCESS (Status)) { ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n", ThisThreadId, AcpiUtGetMutexName (MutexId))); AcpiGbl_AcpiMutexInfo[MutexId].UseCount++; AcpiGbl_AcpiMutexInfo[MutexId].OwnerId = ThisThreadId; } else { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not acquire Mutex [%s] %s\n", ThisThreadId, AcpiUtGetMutexName (MutexId), AcpiFormatException (Status))); } return (Status); }