dbfileio.c revision 284460
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 - 2015, 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
50#if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
51
52#define _COMPONENT          ACPI_CA_DEBUGGER
53        ACPI_MODULE_NAME    ("dbfileio")
54
55#ifdef ACPI_DEBUGGER
56
57/*******************************************************************************
58 *
59 * FUNCTION:    AcpiDbCloseDebugFile
60 *
61 * PARAMETERS:  None
62 *
63 * RETURN:      None
64 *
65 * DESCRIPTION: If open, close the current debug output file
66 *
67 ******************************************************************************/
68
69void
70AcpiDbCloseDebugFile (
71    void)
72{
73
74#ifdef ACPI_APPLICATION
75
76    if (AcpiGbl_DebugFile)
77    {
78       fclose (AcpiGbl_DebugFile);
79       AcpiGbl_DebugFile = NULL;
80       AcpiGbl_DbOutputToFile = FALSE;
81       AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename);
82    }
83#endif
84}
85
86
87/*******************************************************************************
88 *
89 * FUNCTION:    AcpiDbOpenDebugFile
90 *
91 * PARAMETERS:  Name                - Filename to open
92 *
93 * RETURN:      None
94 *
95 * DESCRIPTION: Open a file where debug output will be directed.
96 *
97 ******************************************************************************/
98
99void
100AcpiDbOpenDebugFile (
101    char                    *Name)
102{
103
104#ifdef ACPI_APPLICATION
105
106    AcpiDbCloseDebugFile ();
107    AcpiGbl_DebugFile = fopen (Name, "w+");
108    if (!AcpiGbl_DebugFile)
109    {
110        AcpiOsPrintf ("Could not open debug file %s\n", Name);
111        return;
112    }
113
114    AcpiOsPrintf ("Debug output file %s opened\n", Name);
115    ACPI_STRNCPY (AcpiGbl_DbDebugFilename, Name,
116        sizeof (AcpiGbl_DbDebugFilename));
117    AcpiGbl_DbOutputToFile = TRUE;
118
119#endif
120}
121#endif
122
123
124#ifdef ACPI_APPLICATION
125#include <contrib/dev/acpica/include/acapps.h>
126
127/*******************************************************************************
128 *
129 * FUNCTION:    AeLocalLoadTable
130 *
131 * PARAMETERS:  Table           - pointer to a buffer containing the entire
132 *                                table to be loaded
133 *
134 * RETURN:      Status
135 *
136 * DESCRIPTION: This function is called to load a table from the caller's
137 *              buffer. The buffer must contain an entire ACPI Table including
138 *              a valid header. The header fields will be verified, and if it
139 *              is determined that the table is invalid, the call will fail.
140 *
141 ******************************************************************************/
142
143static ACPI_STATUS
144AeLocalLoadTable (
145    ACPI_TABLE_HEADER       *Table)
146{
147    ACPI_STATUS             Status = AE_OK;
148/*    ACPI_TABLE_DESC         TableInfo; */
149
150
151    ACPI_FUNCTION_TRACE (AeLocalLoadTable);
152#if 0
153
154
155    if (!Table)
156    {
157        return_ACPI_STATUS (AE_BAD_PARAMETER);
158    }
159
160    TableInfo.Pointer = Table;
161    Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL);
162    if (ACPI_FAILURE (Status))
163    {
164        return_ACPI_STATUS (Status);
165    }
166
167    /* Install the new table into the local data structures */
168
169    Status = AcpiTbInitTableDescriptor (&TableInfo);
170    if (ACPI_FAILURE (Status))
171    {
172        if (Status == AE_ALREADY_EXISTS)
173        {
174            /* Table already exists, no error */
175
176            Status = AE_OK;
177        }
178
179        /* Free table allocated by AcpiTbGetTable */
180
181        AcpiTbDeleteSingleTable (&TableInfo);
182        return_ACPI_STATUS (Status);
183    }
184
185#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
186
187    Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
188    if (ACPI_FAILURE (Status))
189    {
190        /* Uninstall table and free the buffer */
191
192        AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT);
193        return_ACPI_STATUS (Status);
194    }
195#endif
196#endif
197
198    return_ACPI_STATUS (Status);
199}
200#endif
201
202
203/*******************************************************************************
204 *
205 * FUNCTION:    AcpiDbGetTableFromFile
206 *
207 * PARAMETERS:  Filename        - File where table is located
208 *              ReturnTable     - Where a pointer to the table is returned
209 *
210 * RETURN:      Status
211 *
212 * DESCRIPTION: Load an ACPI table from a file
213 *
214 ******************************************************************************/
215
216ACPI_STATUS
217AcpiDbGetTableFromFile (
218    char                    *Filename,
219    ACPI_TABLE_HEADER       **ReturnTable,
220    BOOLEAN                 MustBeAmlFile)
221{
222#ifdef ACPI_APPLICATION
223    ACPI_STATUS             Status;
224    ACPI_TABLE_HEADER       *Table;
225    BOOLEAN                 IsAmlTable = TRUE;
226
227
228    Status = AcpiUtReadTableFromFile (Filename, &Table);
229    if (ACPI_FAILURE (Status))
230    {
231        return (Status);
232    }
233
234    if (MustBeAmlFile)
235    {
236        IsAmlTable = AcpiUtIsAmlTable (Table);
237        if (!IsAmlTable)
238        {
239            ACPI_EXCEPTION ((AE_INFO, AE_OK,
240                "Input for -e is not an AML table: "
241                "\"%4.4s\" (must be DSDT/SSDT)",
242                Table->Signature));
243            return (AE_TYPE);
244        }
245    }
246
247    if (IsAmlTable)
248    {
249        /* Attempt to recognize and install the table */
250
251        Status = AeLocalLoadTable (Table);
252        if (ACPI_FAILURE (Status))
253        {
254            if (Status == AE_ALREADY_EXISTS)
255            {
256                AcpiOsPrintf ("Table %4.4s is already installed\n",
257                    Table->Signature);
258            }
259            else
260            {
261                AcpiOsPrintf ("Could not install table, %s\n",
262                    AcpiFormatException (Status));
263            }
264
265            return (Status);
266        }
267
268        AcpiTbPrintTableHeader (0, Table);
269
270        fprintf (stderr,
271            "Acpi table [%4.4s] successfully installed and loaded\n",
272            Table->Signature);
273    }
274
275    AcpiGbl_AcpiHardwarePresent = FALSE;
276    if (ReturnTable)
277    {
278        *ReturnTable = Table;
279    }
280
281
282#endif  /* ACPI_APPLICATION */
283    return (AE_OK);
284}
285
286#endif  /* ACPI_DEBUGGER */
287