xref: /freebsd/sys/contrib/dev/acpica/components/debugger/dbfileio.c (revision 8ef24a0d4b28fe230e20637f56869cc4148cd2ca)
1 /*******************************************************************************
2  *
3  * Module Name: dbfileio - Debugger file I/O commands. These can't usually
4  *              be used when running the debugger in Ring 0 (Kernel mode)
5  *
6  ******************************************************************************/
7 
8 /*
9  * Copyright (C) 2000 - 2016, Intel Corp.
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions, and the following disclaimer,
17  *    without modification.
18  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19  *    substantially similar to the "NO WARRANTY" disclaimer below
20  *    ("Disclaimer") and any redistribution must be conditioned upon
21  *    including a substantially similar Disclaimer requirement for further
22  *    binary redistribution.
23  * 3. Neither the names of the above-listed copyright holders nor the names
24  *    of any contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * Alternatively, this software may be distributed under the terms of the
28  * GNU General Public License ("GPL") version 2 as published by the Free
29  * Software Foundation.
30  *
31  * NO WARRANTY
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42  * POSSIBILITY OF SUCH DAMAGES.
43  */
44 
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acdebug.h>
48 #include <contrib/dev/acpica/include/actables.h>
49 #include <stdio.h>
50 #ifdef ACPI_APPLICATION
51 #include <contrib/dev/acpica/include/acapps.h>
52 #endif
53 
54 #define _COMPONENT          ACPI_CA_DEBUGGER
55         ACPI_MODULE_NAME    ("dbfileio")
56 
57 
58 #ifdef ACPI_DEBUGGER
59 /*******************************************************************************
60  *
61  * FUNCTION:    AcpiDbCloseDebugFile
62  *
63  * PARAMETERS:  None
64  *
65  * RETURN:      None
66  *
67  * DESCRIPTION: If open, close the current debug output file
68  *
69  ******************************************************************************/
70 
71 void
72 AcpiDbCloseDebugFile (
73     void)
74 {
75 
76 #ifdef ACPI_APPLICATION
77 
78     if (AcpiGbl_DebugFile)
79     {
80        fclose (AcpiGbl_DebugFile);
81        AcpiGbl_DebugFile = NULL;
82        AcpiGbl_DbOutputToFile = FALSE;
83        AcpiOsPrintf ("Debug output file %s closed\n",
84             AcpiGbl_DbDebugFilename);
85     }
86 #endif
87 }
88 
89 
90 /*******************************************************************************
91  *
92  * FUNCTION:    AcpiDbOpenDebugFile
93  *
94  * PARAMETERS:  Name                - Filename to open
95  *
96  * RETURN:      None
97  *
98  * DESCRIPTION: Open a file where debug output will be directed.
99  *
100  ******************************************************************************/
101 
102 void
103 AcpiDbOpenDebugFile (
104     char                    *Name)
105 {
106 
107 #ifdef ACPI_APPLICATION
108 
109     AcpiDbCloseDebugFile ();
110     AcpiGbl_DebugFile = fopen (Name, "w+");
111     if (!AcpiGbl_DebugFile)
112     {
113         AcpiOsPrintf ("Could not open debug file %s\n", Name);
114         return;
115     }
116 
117     AcpiOsPrintf ("Debug output file %s opened\n", Name);
118     strncpy (AcpiGbl_DbDebugFilename, Name,
119         sizeof (AcpiGbl_DbDebugFilename));
120     AcpiGbl_DbOutputToFile = TRUE;
121 
122 #endif
123 }
124 #endif
125 
126 
127 /*******************************************************************************
128  *
129  * FUNCTION:    AcpiDbLoadTables
130  *
131  * PARAMETERS:  ListHead        - List of ACPI tables to load
132  *
133  * RETURN:      Status
134  *
135  * DESCRIPTION: Load ACPI tables from a previously constructed table list.
136  *
137  ******************************************************************************/
138 
139 ACPI_STATUS
140 AcpiDbLoadTables (
141     ACPI_NEW_TABLE_DESC     *ListHead)
142 {
143     ACPI_STATUS             Status;
144     ACPI_NEW_TABLE_DESC     *TableListHead;
145     ACPI_TABLE_HEADER       *Table;
146 
147 
148     /* Load all ACPI tables in the list */
149 
150     TableListHead = ListHead;
151     while (TableListHead)
152     {
153         Table = TableListHead->Table;
154 
155         Status = AcpiLoadTable (Table);
156         if (ACPI_FAILURE (Status))
157         {
158             if (Status == AE_ALREADY_EXISTS)
159             {
160                 AcpiOsPrintf ("Table %4.4s is already installed\n",
161                     Table->Signature);
162             }
163             else
164             {
165                 AcpiOsPrintf ("Could not install table, %s\n",
166                     AcpiFormatException (Status));
167             }
168 
169             return (Status);
170         }
171 
172         fprintf (stderr,
173             "Acpi table [%4.4s] successfully installed and loaded\n",
174             Table->Signature);
175 
176         TableListHead = TableListHead->Next;
177     }
178 
179     return (AE_OK);
180 }
181