167754Smsmith/*******************************************************************************
267754Smsmith *
3193267Sjkim * Module Name: dbfileio - Debugger file I/O commands. These can't usually
467754Smsmith *              be used when running the debugger in Ring 0 (Kernel mode)
567754Smsmith *
667754Smsmith ******************************************************************************/
767754Smsmith
8217365Sjkim/*
9245582Sjkim * Copyright (C) 2000 - 2013, Intel Corp.
1070243Smsmith * All rights reserved.
1167754Smsmith *
12217365Sjkim * Redistribution and use in source and binary forms, with or without
13217365Sjkim * modification, are permitted provided that the following conditions
14217365Sjkim * are met:
15217365Sjkim * 1. Redistributions of source code must retain the above copyright
16217365Sjkim *    notice, this list of conditions, and the following disclaimer,
17217365Sjkim *    without modification.
18217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
20217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
21217365Sjkim *    including a substantially similar Disclaimer requirement for further
22217365Sjkim *    binary redistribution.
23217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
24217365Sjkim *    of any contributors may be used to endorse or promote products derived
25217365Sjkim *    from this software without specific prior written permission.
2667754Smsmith *
27217365Sjkim * Alternatively, this software may be distributed under the terms of the
28217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
29217365Sjkim * Software Foundation.
3067754Smsmith *
31217365Sjkim * NO WARRANTY
32217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
43217365Sjkim */
4467754Smsmith
4567754Smsmith
46193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
47193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
48193341Sjkim#include <contrib/dev/acpica/include/acdebug.h>
49193267Sjkim
50193267Sjkim#ifdef ACPI_APPLICATION
51193341Sjkim#include <contrib/dev/acpica/include/actables.h>
52193267Sjkim#endif
5367754Smsmith
54235945Sjkim#ifdef ACPI_ASL_COMPILER
55235945Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
56235945Sjkim#endif
57235945Sjkim
58102550Siwasaki#if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
5967754Smsmith
60102550Siwasaki#define _COMPONENT          ACPI_CA_DEBUGGER
6191116Smsmith        ACPI_MODULE_NAME    ("dbfileio")
6267754Smsmith
6384491Smsmith/*
64193267Sjkim * NOTE: this is here for lack of a better place. It is used in all
6584491Smsmith * flavors of the debugger, need LCD file
6684491Smsmith */
6767754Smsmith#ifdef ACPI_APPLICATION
6867754Smsmith#include <stdio.h>
6983174SmsmithFILE                        *AcpiGbl_DebugFile = NULL;
7067754Smsmith#endif
7167754Smsmith
7267754Smsmith
73102550Siwasaki#ifdef ACPI_DEBUGGER
74151937Sjkim
75151937Sjkim/* Local prototypes */
76151937Sjkim
77151940Sjkim#ifdef ACPI_APPLICATION
78151940Sjkim
79151937Sjkimstatic ACPI_STATUS
80151937SjkimAcpiDbCheckTextModeCorruption (
81151937Sjkim    UINT8                   *Table,
82151937Sjkim    UINT32                  TableLength,
83151937Sjkim    UINT32                  FileLength);
84151937Sjkim
85151940Sjkim#endif
86151937Sjkim
8767754Smsmith/*******************************************************************************
8867754Smsmith *
8967754Smsmith * FUNCTION:    AcpiDbCloseDebugFile
9067754Smsmith *
9167754Smsmith * PARAMETERS:  None
9267754Smsmith *
93151937Sjkim * RETURN:      None
9467754Smsmith *
9567754Smsmith * DESCRIPTION: If open, close the current debug output file
9667754Smsmith *
9767754Smsmith ******************************************************************************/
9867754Smsmith
9967754Smsmithvoid
10067754SmsmithAcpiDbCloseDebugFile (
10167754Smsmith    void)
10267754Smsmith{
10367754Smsmith
10467754Smsmith#ifdef ACPI_APPLICATION
10567754Smsmith
10683174Smsmith    if (AcpiGbl_DebugFile)
10767754Smsmith    {
10883174Smsmith       fclose (AcpiGbl_DebugFile);
10983174Smsmith       AcpiGbl_DebugFile = NULL;
11083174Smsmith       AcpiGbl_DbOutputToFile = FALSE;
11183174Smsmith       AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename);
11267754Smsmith    }
11367754Smsmith#endif
11467754Smsmith}
11567754Smsmith
11667754Smsmith
11767754Smsmith/*******************************************************************************
11867754Smsmith *
11967754Smsmith * FUNCTION:    AcpiDbOpenDebugFile
12067754Smsmith *
12167754Smsmith * PARAMETERS:  Name                - Filename to open
12267754Smsmith *
123151937Sjkim * RETURN:      None
12467754Smsmith *
12567754Smsmith * DESCRIPTION: Open a file where debug output will be directed.
12667754Smsmith *
12767754Smsmith ******************************************************************************/
12867754Smsmith
12967754Smsmithvoid
13067754SmsmithAcpiDbOpenDebugFile (
131114237Snjl    char                    *Name)
13267754Smsmith{
13367754Smsmith
13467754Smsmith#ifdef ACPI_APPLICATION
13567754Smsmith
13667754Smsmith    AcpiDbCloseDebugFile ();
13783174Smsmith    AcpiGbl_DebugFile = fopen (Name, "w+");
138243347Sjkim    if (!AcpiGbl_DebugFile)
13967754Smsmith    {
14073561Smsmith        AcpiOsPrintf ("Could not open debug file %s\n", Name);
141243347Sjkim        return;
14273561Smsmith    }
14367754Smsmith
144243347Sjkim    AcpiOsPrintf ("Debug output file %s opened\n", Name);
145254745Sjkim    ACPI_STRNCPY (AcpiGbl_DbDebugFilename, Name,
146254745Sjkim        sizeof (AcpiGbl_DbDebugFilename));
147243347Sjkim    AcpiGbl_DbOutputToFile = TRUE;
148243347Sjkim
14967754Smsmith#endif
15067754Smsmith}
151100966Siwasaki#endif
15267754Smsmith
15367754Smsmith
15467754Smsmith#ifdef ACPI_APPLICATION
15567754Smsmith/*******************************************************************************
15667754Smsmith *
157117521Snjl * FUNCTION:    AcpiDbCheckTextModeCorruption
158117521Snjl *
159117521Snjl * PARAMETERS:  Table           - Table buffer
160117521Snjl *              TableLength     - Length of table from the table header
161117521Snjl *              FileLength      - Length of the file that contains the table
162117521Snjl *
163117521Snjl * RETURN:      Status
164117521Snjl *
165117521Snjl * DESCRIPTION: Check table for text mode file corruption where all linefeed
166117521Snjl *              characters (LF) have been replaced by carriage return linefeed
167117521Snjl *              pairs (CR/LF).
168117521Snjl *
169117521Snjl ******************************************************************************/
170117521Snjl
171117521Snjlstatic ACPI_STATUS
172117521SnjlAcpiDbCheckTextModeCorruption (
173117521Snjl    UINT8                   *Table,
174117521Snjl    UINT32                  TableLength,
175117521Snjl    UINT32                  FileLength)
176117521Snjl{
177117521Snjl    UINT32                  i;
178117521Snjl    UINT32                  Pairs = 0;
179117521Snjl
180117521Snjl
181117521Snjl    if (TableLength != FileLength)
182117521Snjl    {
183167802Sjkim        ACPI_WARNING ((AE_INFO,
184167802Sjkim            "File length (0x%X) is not the same as the table length (0x%X)",
185151937Sjkim            FileLength, TableLength));
186117521Snjl    }
187117521Snjl
188117521Snjl    /* Scan entire table to determine if each LF has been prefixed with a CR */
189117521Snjl
190117521Snjl    for (i = 1; i < FileLength; i++)
191117521Snjl    {
192117521Snjl        if (Table[i] == 0x0A)
193117521Snjl        {
194117521Snjl            if (Table[i - 1] != 0x0D)
195117521Snjl            {
196193267Sjkim                /* The LF does not have a preceding CR, table not corrupted */
197117521Snjl
198117521Snjl                return (AE_OK);
199117521Snjl            }
200117521Snjl            else
201117521Snjl            {
202117521Snjl                /* Found a CR/LF pair */
203117521Snjl
204117521Snjl                Pairs++;
205117521Snjl            }
206117521Snjl            i++;
207117521Snjl        }
208117521Snjl    }
209117521Snjl
210167802Sjkim    if (!Pairs)
211167802Sjkim    {
212167802Sjkim        return (AE_OK);
213167802Sjkim    }
214167802Sjkim
215123315Snjl    /*
216117521Snjl     * Entire table scanned, each CR is part of a CR/LF pair --
217117521Snjl     * meaning that the table was treated as a text file somewhere.
218117521Snjl     *
219117521Snjl     * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the
220123315Snjl     * original table are left untouched by the text conversion process --
221117521Snjl     * meaning that we cannot simply replace CR/LF pairs with LFs.
222117521Snjl     */
223117521Snjl    AcpiOsPrintf ("Table has been corrupted by text mode conversion\n");
224209746Sjkim    AcpiOsPrintf ("All LFs (%u) were changed to CR/LF pairs\n", Pairs);
225117521Snjl    AcpiOsPrintf ("Table cannot be repaired!\n");
226117521Snjl    return (AE_BAD_VALUE);
227117521Snjl}
228117521Snjl
229117521Snjl
230117521Snjl/*******************************************************************************
231117521Snjl *
232114237Snjl * FUNCTION:    AcpiDbReadTable
23367754Smsmith *
23467754Smsmith * PARAMETERS:  fp              - File that contains table
235114237Snjl *              Table           - Return value, buffer with table
236114237Snjl *              TableLength     - Return value, length of table
23767754Smsmith *
23867754Smsmith * RETURN:      Status
23967754Smsmith *
24067754Smsmith * DESCRIPTION: Load the DSDT from the file pointer
24167754Smsmith *
24267754Smsmith ******************************************************************************/
24367754Smsmith
24499679Siwasakistatic ACPI_STATUS
245114237SnjlAcpiDbReadTable (
24667754Smsmith    FILE                    *fp,
247114237Snjl    ACPI_TABLE_HEADER       **Table,
24867754Smsmith    UINT32                  *TableLength)
24967754Smsmith{
25067754Smsmith    ACPI_TABLE_HEADER       TableHeader;
25167754Smsmith    UINT32                  Actual;
25269450Smsmith    ACPI_STATUS             Status;
253117521Snjl    UINT32                  FileSize;
254167802Sjkim    BOOLEAN                 StandardHeader = TRUE;
25567754Smsmith
25667754Smsmith
257167802Sjkim    /* Get the file size */
258167802Sjkim
259117521Snjl    fseek (fp, 0, SEEK_END);
260151937Sjkim    FileSize = (UINT32) ftell (fp);
261117521Snjl    fseek (fp, 0, SEEK_SET);
262117521Snjl
263167802Sjkim    if (FileSize < 4)
26467754Smsmith    {
265151937Sjkim        return (AE_BAD_HEADER);
26667754Smsmith    }
26767754Smsmith
268167802Sjkim    /* Read the signature */
26969450Smsmith
270167802Sjkim    if (fread (&TableHeader, 1, 4, fp) != 4)
27167754Smsmith    {
272167802Sjkim        AcpiOsPrintf ("Could not read the table signature\n");
273167802Sjkim        return (AE_BAD_HEADER);
27467754Smsmith    }
27567754Smsmith
276167802Sjkim    fseek (fp, 0, SEEK_SET);
277151937Sjkim
278254745Sjkim    /* The RSDP table does not have standard ACPI header */
279167802Sjkim
280254745Sjkim    if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD "))
281151937Sjkim    {
282167802Sjkim        *TableLength = FileSize;
283167802Sjkim        StandardHeader = FALSE;
284151937Sjkim    }
285167802Sjkim    else
286167802Sjkim    {
287193267Sjkim        /* Read the table header */
288151937Sjkim
289243347Sjkim        if (fread (&TableHeader, 1, sizeof (ACPI_TABLE_HEADER), fp) !=
290167802Sjkim                sizeof (ACPI_TABLE_HEADER))
291167802Sjkim        {
292167802Sjkim            AcpiOsPrintf ("Could not read the table header\n");
293167802Sjkim            return (AE_BAD_HEADER);
294167802Sjkim        }
29569450Smsmith
296167802Sjkim#if 0
297167802Sjkim        /* Validate the table header/length */
298167802Sjkim
299167802Sjkim        Status = AcpiTbValidateTableHeader (&TableHeader);
300167802Sjkim        if (ACPI_FAILURE (Status))
301167802Sjkim        {
302167802Sjkim            AcpiOsPrintf ("Table header is invalid!\n");
303167802Sjkim            return (Status);
304167802Sjkim        }
305167802Sjkim#endif
306167802Sjkim
307167802Sjkim        /* File size must be at least as long as the Header-specified length */
308167802Sjkim
309167802Sjkim        if (TableHeader.Length > FileSize)
310167802Sjkim        {
311167802Sjkim            AcpiOsPrintf (
312167802Sjkim                "TableHeader length [0x%X] greater than the input file size [0x%X]\n",
313167802Sjkim                TableHeader.Length, FileSize);
314235945Sjkim
315235945Sjkim#ifdef ACPI_ASL_COMPILER
316235945Sjkim            Status = FlCheckForAscii (fp, NULL, FALSE);
317235945Sjkim            if (ACPI_SUCCESS (Status))
318235945Sjkim            {
319235945Sjkim                AcpiOsPrintf ("File appears to be ASCII only, must be binary\n",
320235945Sjkim                    TableHeader.Length, FileSize);
321235945Sjkim            }
322235945Sjkim#endif
323167802Sjkim            return (AE_BAD_HEADER);
324167802Sjkim        }
325167802Sjkim
326167802Sjkim#ifdef ACPI_OBSOLETE_CODE
327167802Sjkim        /* We only support a limited number of table types */
328167802Sjkim
329241973Sjkim        if (!ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_DSDT) &&
330241973Sjkim            !ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_PSDT) &&
331241973Sjkim            !ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_SSDT))
332167802Sjkim        {
333167802Sjkim            AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n",
334167802Sjkim                (char *) TableHeader.Signature);
335167802Sjkim            ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
336167802Sjkim            return (AE_ERROR);
337167802Sjkim        }
338167802Sjkim#endif
339167802Sjkim
340167802Sjkim        *TableLength = TableHeader.Length;
34169450Smsmith    }
34269450Smsmith
34367754Smsmith    /* Allocate a buffer for the table */
34467754Smsmith
345167802Sjkim    *Table = AcpiOsAllocate ((size_t) FileSize);
346114237Snjl    if (!*Table)
34767754Smsmith    {
348151937Sjkim        AcpiOsPrintf (
349151937Sjkim            "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
350167802Sjkim            TableHeader.Signature, *TableLength);
35167754Smsmith        return (AE_NO_MEMORY);
35267754Smsmith    }
35367754Smsmith
35467754Smsmith    /* Get the rest of the table */
35567754Smsmith
356117521Snjl    fseek (fp, 0, SEEK_SET);
357117521Snjl    Actual = fread (*Table, 1, (size_t) FileSize, fp);
358117521Snjl    if (Actual == FileSize)
35967754Smsmith    {
360167802Sjkim        if (StandardHeader)
361167802Sjkim        {
362167802Sjkim            /* Now validate the checksum */
363107325Siwasaki
364202771Sjkim            Status = AcpiTbVerifyChecksum ((void *) *Table,
365167802Sjkim                        ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length);
366117521Snjl
367167802Sjkim            if (Status == AE_BAD_CHECKSUM)
368167802Sjkim            {
369167802Sjkim                Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table,
370167802Sjkim                            FileSize, (*Table)->Length);
371167802Sjkim                return (Status);
372167802Sjkim            }
373117521Snjl        }
37467754Smsmith        return (AE_OK);
37567754Smsmith    }
37667754Smsmith
37767754Smsmith    if (Actual > 0)
37867754Smsmith    {
379117521Snjl        AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n",
380117521Snjl            FileSize, Actual);
38184491Smsmith        return (AE_OK);
38267754Smsmith    }
38367754Smsmith
38467754Smsmith    AcpiOsPrintf ("Error - could not read the table file\n");
385114237Snjl    AcpiOsFree (*Table);
386114237Snjl    *Table = NULL;
38767754Smsmith    *TableLength = 0;
38867754Smsmith    return (AE_ERROR);
38967754Smsmith}
39067754Smsmith
39167754Smsmith
39267754Smsmith/*******************************************************************************
39367754Smsmith *
39467754Smsmith * FUNCTION:    AeLocalLoadTable
39567754Smsmith *
396114237Snjl * PARAMETERS:  Table           - pointer to a buffer containing the entire
39767754Smsmith *                                table to be loaded
39867754Smsmith *
39967754Smsmith * RETURN:      Status
40067754Smsmith *
40167754Smsmith * DESCRIPTION: This function is called to load a table from the caller's
402193267Sjkim *              buffer. The buffer must contain an entire ACPI Table including
403193267Sjkim *              a valid header. The header fields will be verified, and if it
40467754Smsmith *              is determined that the table is invalid, the call will fail.
40567754Smsmith *
40667754Smsmith ******************************************************************************/
40767754Smsmith
408151937Sjkimstatic ACPI_STATUS
40967754SmsmithAeLocalLoadTable (
410114237Snjl    ACPI_TABLE_HEADER       *Table)
41167754Smsmith{
412167802Sjkim    ACPI_STATUS             Status = AE_OK;
413167802Sjkim/*    ACPI_TABLE_DESC         TableInfo; */
41467754Smsmith
41567754Smsmith
416167802Sjkim    ACPI_FUNCTION_TRACE (AeLocalLoadTable);
417167802Sjkim#if 0
41867754Smsmith
419114237Snjl
420114237Snjl    if (!Table)
42167754Smsmith    {
42267754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
42367754Smsmith    }
42467754Smsmith
425114237Snjl    TableInfo.Pointer = Table;
426114237Snjl    Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL);
427100966Siwasaki    if (ACPI_FAILURE (Status))
428100966Siwasaki    {
429100966Siwasaki        return_ACPI_STATUS (Status);
430100966Siwasaki    }
431100966Siwasaki
43267754Smsmith    /* Install the new table into the local data structures */
43367754Smsmith
43499679Siwasaki    Status = AcpiTbInstallTable (&TableInfo);
43567754Smsmith    if (ACPI_FAILURE (Status))
43667754Smsmith    {
437151937Sjkim        if (Status == AE_ALREADY_EXISTS)
438151937Sjkim        {
439151937Sjkim            /* Table already exists, no error */
440151937Sjkim
441151937Sjkim            Status = AE_OK;
442151937Sjkim        }
443151937Sjkim
44467754Smsmith        /* Free table allocated by AcpiTbGetTable */
44567754Smsmith
44667754Smsmith        AcpiTbDeleteSingleTable (&TableInfo);
44767754Smsmith        return_ACPI_STATUS (Status);
44867754Smsmith    }
44967754Smsmith
450114237Snjl#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
45167754Smsmith
45267754Smsmith    Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
45367754Smsmith    if (ACPI_FAILURE (Status))
45467754Smsmith    {
45567754Smsmith        /* Uninstall table and free the buffer */
45667754Smsmith
457167802Sjkim        AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT);
45867754Smsmith        return_ACPI_STATUS (Status);
45967754Smsmith    }
46067754Smsmith#endif
461167802Sjkim#endif
46267754Smsmith
46367754Smsmith    return_ACPI_STATUS (Status);
46467754Smsmith}
46567754Smsmith
46667754Smsmith
467107325Siwasaki/*******************************************************************************
468107325Siwasaki *
469114237Snjl * FUNCTION:    AcpiDbReadTableFromFile
470107325Siwasaki *
471114237Snjl * PARAMETERS:  Filename         - File where table is located
472114237Snjl *              Table            - Where a pointer to the table is returned
473107325Siwasaki *
474107325Siwasaki * RETURN:      Status
475107325Siwasaki *
476107325Siwasaki * DESCRIPTION: Get an ACPI table from a file
477107325Siwasaki *
478107325Siwasaki ******************************************************************************/
479107325Siwasaki
48067754SmsmithACPI_STATUS
481114237SnjlAcpiDbReadTableFromFile (
482114237Snjl    char                    *Filename,
483114237Snjl    ACPI_TABLE_HEADER       **Table)
48467754Smsmith{
485243347Sjkim    FILE                    *File;
48699146Siwasaki    UINT32                  TableLength;
48767754Smsmith    ACPI_STATUS             Status;
48867754Smsmith
489107325Siwasaki
49067754Smsmith    /* Open the file */
49167754Smsmith
492243347Sjkim    File = fopen (Filename, "rb");
493243347Sjkim    if (!File)
49467754Smsmith    {
495114237Snjl        AcpiOsPrintf ("Could not open input file %s\n", Filename);
49667754Smsmith        return (AE_ERROR);
49767754Smsmith    }
49867754Smsmith
49967754Smsmith    /* Get the entire file */
50067754Smsmith
501100966Siwasaki    fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
502243347Sjkim    Status = AcpiDbReadTable (File, Table, &TableLength);
503243347Sjkim    fclose(File);
50467754Smsmith
50567754Smsmith    if (ACPI_FAILURE (Status))
50667754Smsmith    {
507151937Sjkim        AcpiOsPrintf ("Could not get table from the file\n");
50867754Smsmith        return (Status);
50967754Smsmith    }
51067754Smsmith
51199146Siwasaki    return (AE_OK);
51299146Siwasaki }
51399146Siwasaki#endif
51467754Smsmith
515107325Siwasaki
51699146Siwasaki/*******************************************************************************
51799146Siwasaki *
518114237Snjl * FUNCTION:    AcpiDbGetTableFromFile
51999146Siwasaki *
520151937Sjkim * PARAMETERS:  Filename        - File where table is located
521151937Sjkim *              ReturnTable     - Where a pointer to the table is returned
52299146Siwasaki *
52399146Siwasaki * RETURN:      Status
52499146Siwasaki *
52599146Siwasaki * DESCRIPTION: Load an ACPI table from a file
52699146Siwasaki *
52799146Siwasaki ******************************************************************************/
52899146Siwasaki
52999146SiwasakiACPI_STATUS
530114237SnjlAcpiDbGetTableFromFile (
531114237Snjl    char                    *Filename,
532114237Snjl    ACPI_TABLE_HEADER       **ReturnTable)
53399146Siwasaki{
53499146Siwasaki#ifdef ACPI_APPLICATION
53599146Siwasaki    ACPI_STATUS             Status;
536114237Snjl    ACPI_TABLE_HEADER       *Table;
537167802Sjkim    BOOLEAN                 IsAmlTable = TRUE;
53899146Siwasaki
53999146Siwasaki
540114237Snjl    Status = AcpiDbReadTableFromFile (Filename, &Table);
54199146Siwasaki    if (ACPI_FAILURE (Status))
54299146Siwasaki    {
54399146Siwasaki        return (Status);
54499146Siwasaki    }
54599146Siwasaki
546167802Sjkim#ifdef ACPI_DATA_TABLE_DISASSEMBLY
547167802Sjkim    IsAmlTable = AcpiUtIsAmlTable (Table);
548167802Sjkim#endif
54999146Siwasaki
550167802Sjkim    if (IsAmlTable)
55167754Smsmith    {
552167802Sjkim        /* Attempt to recognize and install the table */
553167802Sjkim
554167802Sjkim        Status = AeLocalLoadTable (Table);
555167802Sjkim        if (ACPI_FAILURE (Status))
55667754Smsmith        {
557167802Sjkim            if (Status == AE_ALREADY_EXISTS)
558167802Sjkim            {
559167802Sjkim                AcpiOsPrintf ("Table %4.4s is already installed\n",
560167802Sjkim                    Table->Signature);
561167802Sjkim            }
562167802Sjkim            else
563167802Sjkim            {
564167802Sjkim                AcpiOsPrintf ("Could not install table, %s\n",
565167802Sjkim                    AcpiFormatException (Status));
566167802Sjkim            }
567167802Sjkim
568167802Sjkim            return (Status);
56967754Smsmith        }
57080062Smsmith
571167802Sjkim        fprintf (stderr,
572167802Sjkim            "Acpi table [%4.4s] successfully installed and loaded\n",
573167802Sjkim            Table->Signature);
57467754Smsmith    }
57567754Smsmith
57667754Smsmith    AcpiGbl_AcpiHardwarePresent = FALSE;
577114237Snjl    if (ReturnTable)
578114237Snjl    {
579114237Snjl        *ReturnTable = Table;
580114237Snjl    }
58167754Smsmith
582114237Snjl
58367754Smsmith#endif  /* ACPI_APPLICATION */
58467754Smsmith    return (AE_OK);
58567754Smsmith}
58667754Smsmith
587102550Siwasaki#endif  /* ACPI_DEBUGGER */
588