Sync ACPICA with Intel's version 20151124.
[dragonfly.git] / sys / dev / acpica / Osd / OsdDebug.c
1 /*-
2  * Copyright (c) 2000 Michael Smith
3  * Copyright (c) 2000 BSDi
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD: head/sys/dev/acpica/Osd/OsdDebug.c 222544 2011-05-31 19:45:58Z jkim $
28  */
29
30 /*
31  * Debugging Support
32  */
33
34 #include "opt_ddb.h"
35
36 #include <sys/param.h>
37 #include <sys/kernel.h>
38 #include <sys/bus.h>
39 #include <ddb/ddb.h>
40 #include <ddb/db_output.h>
41
42 #include "acpi.h"
43 #include "accommon.h"
44 #include "acpivar.h"
45 #include "acdebug.h"
46
47 ACPI_STATUS
48 AcpiOsGetLine(char *Buffer, UINT32 BufferLength, UINT32 *BytesRead)
49 {
50 #ifdef DDB
51         char *cp;
52
53         cp = Buffer;
54         if (db_readline(Buffer, BufferLength) > 0)
55                 while (*cp != '\0' && *cp != '\n' && *cp != '\r')
56                         cp++;
57         *cp = '\0';
58         if (BytesRead != NULL)
59                 *BytesRead = cp - Buffer;
60         return (AE_OK);
61 #else
62         kprintf("AcpiOsGetLine called but no input support");
63         return (AE_NOT_EXIST);
64 #endif /* DDB */
65 }
66
67 ACPI_STATUS
68 AcpiOsSignal(UINT32 Function, void *Info)
69 {
70     ACPI_SIGNAL_FATAL_INFO      *fatal;
71     
72     switch (Function) {
73     case ACPI_SIGNAL_FATAL:
74         fatal = (ACPI_SIGNAL_FATAL_INFO *)Info;
75         kprintf("ACPI fatal signal, type 0x%x code 0x%x argument 0x%x",
76               fatal->Type, fatal->Code, fatal->Argument);
77 #ifdef ACPI_DEBUG
78         Debugger("AcpiOsSignal");
79 #endif
80         break;
81         
82     case ACPI_SIGNAL_BREAKPOINT:
83 #ifdef ACPI_DEBUG
84         Debugger((char *)Info);
85 #endif
86         break;
87
88     default:
89         return (AE_BAD_PARAMETER);
90     }
91
92     return (AE_OK);
93 }
94
95 #ifdef ACPI_DEBUGGER
96 DB_COMMAND(acpidb, db_cmd_acpidb)
97 {
98     kprintf("Entering ACPICA debugger...\n");
99     while (!AcpiGbl_DbTerminateLoop) {
100         AcpiDbSetOutputDestination(ACPI_DB_CONSOLE_OUTPUT);
101         if (!AcpiGbl_MethodExecuting)
102             AcpiOsPrintf("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
103         else
104             AcpiOsPrintf("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
105         AcpiOsGetLine(AcpiGbl_DbLineBuf, ACPI_DB_LINE_BUFFER_SIZE, NULL);
106         AcpiDbCommandDispatch(AcpiGbl_DbLineBuf, NULL, NULL);
107     }
108     AcpiGbl_DbTerminateLoop = FALSE;
109     kprintf("Leaving ACPICA debugger...\n");
110 }
111 #endif /* ACPI_DEBUGGER */