Sync ACPICA with Intel's version 20161222.
[dragonfly.git] / sys / contrib / dev / acpica / source / os_specific / service_layers / osgendbg.c
blob1b7079e1c8136eac976b5cb718b3f2d569a24212
1 /******************************************************************************
3 * Module Name: osgendbg - Generic debugger command singalling
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acdebug.h"
49 #define _COMPONENT ACPI_CA_DEBUGGER
50 ACPI_MODULE_NAME ("osgendbg")
53 /* Local prototypes */
55 static void
56 AcpiDbRunRemoteDebugger (
57 char *BatchBuffer);
60 static ACPI_MUTEX AcpiGbl_DbCommandReady;
61 static ACPI_MUTEX AcpiGbl_DbCommandComplete;
62 static BOOLEAN AcpiGbl_DbCommandSignalsInitialized = FALSE;
64 /******************************************************************************
66 * FUNCTION: AcpiDbRunRemoteDebugger
68 * PARAMETERS: BatchBuffer - Buffer containing commands running in
69 * the batch mode
71 * RETURN: None
73 * DESCRIPTION: Run multi-threading debugger remotely
75 *****************************************************************************/
77 static void
78 AcpiDbRunRemoteDebugger (
79 char *BatchBuffer)
81 ACPI_STATUS Status;
82 char *Ptr = BatchBuffer;
83 char *Cmd = Ptr;
86 while (!AcpiGbl_DbTerminateLoop)
88 if (BatchBuffer)
90 if (*Ptr)
92 while (*Ptr)
94 if (*Ptr == ',')
96 /* Convert commas to spaces */
97 *Ptr = ' ';
99 else if (*Ptr == ';')
101 *Ptr = '\0';
102 continue;
105 Ptr++;
108 strncpy (AcpiGbl_DbLineBuf, Cmd, ACPI_DB_LINE_BUFFER_SIZE);
109 Ptr++;
110 Cmd = Ptr;
112 else
114 return;
117 else
119 /* Force output to console until a command is entered */
121 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
123 /* Different prompt if method is executing */
125 if (!AcpiGbl_MethodExecuting)
127 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
129 else
131 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
134 /* Get the user input line */
136 Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
137 ACPI_DB_LINE_BUFFER_SIZE, NULL);
138 if (ACPI_FAILURE (Status))
140 return;
145 * Signal the debug thread that we have a command to execute,
146 * and wait for the command to complete.
148 AcpiOsReleaseMutex (AcpiGbl_DbCommandReady);
150 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete,
151 ACPI_WAIT_FOREVER);
152 if (ACPI_FAILURE (Status))
154 return;
160 /******************************************************************************
162 * FUNCTION: AcpiOsWaitCommandReady
164 * PARAMETERS: None
166 * RETURN: Status
168 * DESCRIPTION: Negotiate with the debugger foreground thread (the user
169 * thread) to wait the readiness of a command.
171 *****************************************************************************/
173 ACPI_STATUS
174 AcpiOsWaitCommandReady (
175 void)
177 ACPI_STATUS Status = AE_OK;
180 if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED)
182 Status = AE_TIME;
184 while (Status == AE_TIME)
186 if (AcpiGbl_DbTerminateLoop)
188 Status = AE_CTRL_TERMINATE;
190 else
192 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady, 1000);
196 else
198 /* Force output to console until a command is entered */
200 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
202 /* Different prompt if method is executing */
204 if (!AcpiGbl_MethodExecuting)
206 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
208 else
210 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
213 /* Get the user input line */
215 Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
216 ACPI_DB_LINE_BUFFER_SIZE, NULL);
219 if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
221 ACPI_EXCEPTION ((AE_INFO, Status,
222 "While parsing/handling command line"));
224 return (Status);
228 /******************************************************************************
230 * FUNCTION: AcpiOsNotifyCommandComplete
232 * PARAMETERS: void
234 * RETURN: Status
236 * DESCRIPTION: Negotiate with the debugger foreground thread (the user
237 * thread) to notify the completion of a command.
239 *****************************************************************************/
241 ACPI_STATUS
242 AcpiOsNotifyCommandComplete (
243 void)
246 if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED)
248 AcpiOsReleaseMutex (AcpiGbl_DbCommandComplete);
250 return (AE_OK);
254 /******************************************************************************
256 * FUNCTION: AcpiOsInitializeDebugger
258 * PARAMETERS: None
260 * RETURN: Status
262 * DESCRIPTION: Initialize OSPM specific part of the debugger
264 *****************************************************************************/
266 ACPI_STATUS
267 AcpiOsInitializeDebugger (
268 void)
270 ACPI_STATUS Status;
273 /* Create command signals */
275 Status = AcpiOsCreateMutex (&AcpiGbl_DbCommandReady);
276 if (ACPI_FAILURE (Status))
278 return (Status);
280 Status = AcpiOsCreateMutex (&AcpiGbl_DbCommandComplete);
281 if (ACPI_FAILURE (Status))
283 goto ErrorReady;
286 /* Initialize the states of the command signals */
288 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete,
289 ACPI_WAIT_FOREVER);
290 if (ACPI_FAILURE (Status))
292 goto ErrorComplete;
294 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady,
295 ACPI_WAIT_FOREVER);
296 if (ACPI_FAILURE (Status))
298 goto ErrorComplete;
301 AcpiGbl_DbCommandSignalsInitialized = TRUE;
302 return (Status);
304 ErrorComplete:
305 AcpiOsDeleteMutex (AcpiGbl_DbCommandComplete);
306 ErrorReady:
307 AcpiOsDeleteMutex (AcpiGbl_DbCommandReady);
308 return (Status);
312 /******************************************************************************
314 * FUNCTION: AcpiOsTerminateDebugger
316 * PARAMETERS: None
318 * RETURN: None
320 * DESCRIPTION: Terminate signals used by the multi-threading debugger
322 *****************************************************************************/
324 void
325 AcpiOsTerminateDebugger (
326 void)
329 if (AcpiGbl_DbCommandSignalsInitialized)
331 AcpiOsDeleteMutex (AcpiGbl_DbCommandReady);
332 AcpiOsDeleteMutex (AcpiGbl_DbCommandComplete);
337 /******************************************************************************
339 * FUNCTION: AcpiRunDebugger
341 * PARAMETERS: BatchBuffer - Buffer containing commands running in
342 * the batch mode
344 * RETURN: None
346 * DESCRIPTION: Run a local/remote debugger
348 *****************************************************************************/
350 void
351 AcpiRunDebugger (
352 char *BatchBuffer)
354 /* Check for single or multithreaded debug */
356 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
358 AcpiDbRunRemoteDebugger (BatchBuffer);
360 else
362 AcpiDbUserCommands ();
366 ACPI_EXPORT_SYMBOL (AcpiRunDebugger)