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/*
9217365Sjkim * Copyright (C) 2000 - 2011, 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
54102550Siwasaki#if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
5567754Smsmith
56102550Siwasaki#define _COMPONENT          ACPI_CA_DEBUGGER
5791116Smsmith        ACPI_MODULE_NAME    ("dbfileio")
5867754Smsmith
5984491Smsmith/*
60193267Sjkim * NOTE: this is here for lack of a better place. It is used in all
6184491Smsmith * flavors of the debugger, need LCD file
6284491Smsmith */
6367754Smsmith#ifdef ACPI_APPLICATION
6467754Smsmith#include <stdio.h>
6583174SmsmithFILE                        *AcpiGbl_DebugFile = NULL;
6667754Smsmith#endif
6767754Smsmith
6867754Smsmith
69102550Siwasaki#ifdef ACPI_DEBUGGER
70151937Sjkim
71151937Sjkim/* Local prototypes */
72151937Sjkim
73151940Sjkim#ifdef ACPI_APPLICATION
74151940Sjkim
75151937Sjkimstatic ACPI_STATUS
76151937SjkimAcpiDbCheckTextModeCorruption (
77151937Sjkim    UINT8                   *Table,
78151937Sjkim    UINT32                  TableLength,
79151937Sjkim    UINT32                  FileLength);
80151937Sjkim
81151940Sjkim#endif
82151937Sjkim
8367754Smsmith/*******************************************************************************
8467754Smsmith *
8567754Smsmith * FUNCTION:    AcpiDbCloseDebugFile
8667754Smsmith *
8767754Smsmith * PARAMETERS:  None
8867754Smsmith *
89151937Sjkim * RETURN:      None
9067754Smsmith *
9167754Smsmith * DESCRIPTION: If open, close the current debug output file
9267754Smsmith *
9367754Smsmith ******************************************************************************/
9467754Smsmith
9567754Smsmithvoid
9667754SmsmithAcpiDbCloseDebugFile (
9767754Smsmith    void)
9867754Smsmith{
9967754Smsmith
10067754Smsmith#ifdef ACPI_APPLICATION
10167754Smsmith
10283174Smsmith    if (AcpiGbl_DebugFile)
10367754Smsmith    {
10483174Smsmith       fclose (AcpiGbl_DebugFile);
10583174Smsmith       AcpiGbl_DebugFile = NULL;
10683174Smsmith       AcpiGbl_DbOutputToFile = FALSE;
10783174Smsmith       AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename);
10867754Smsmith    }
10967754Smsmith#endif
11067754Smsmith}
11167754Smsmith
11267754Smsmith
11367754Smsmith/*******************************************************************************
11467754Smsmith *
11567754Smsmith * FUNCTION:    AcpiDbOpenDebugFile
11667754Smsmith *
11767754Smsmith * PARAMETERS:  Name                - Filename to open
11867754Smsmith *
119151937Sjkim * RETURN:      None
12067754Smsmith *
12167754Smsmith * DESCRIPTION: Open a file where debug output will be directed.
12267754Smsmith *
12367754Smsmith ******************************************************************************/
12467754Smsmith
12567754Smsmithvoid
12667754SmsmithAcpiDbOpenDebugFile (
127114237Snjl    char                    *Name)
12867754Smsmith{
12967754Smsmith
13067754Smsmith#ifdef ACPI_APPLICATION
13167754Smsmith
13267754Smsmith    AcpiDbCloseDebugFile ();
13383174Smsmith    AcpiGbl_DebugFile = fopen (Name, "w+");
13483174Smsmith    if (AcpiGbl_DebugFile)
13567754Smsmith    {
13667754Smsmith        AcpiOsPrintf ("Debug output file %s opened\n", Name);
13791116Smsmith        ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name);
13883174Smsmith        AcpiGbl_DbOutputToFile = TRUE;
13967754Smsmith    }
14073561Smsmith    else
14173561Smsmith    {
14273561Smsmith        AcpiOsPrintf ("Could not open debug file %s\n", Name);
14373561Smsmith    }
14467754Smsmith
14567754Smsmith#endif
14667754Smsmith}
147100966Siwasaki#endif
14867754Smsmith
14967754Smsmith
15067754Smsmith#ifdef ACPI_APPLICATION
15167754Smsmith/*******************************************************************************
15267754Smsmith *
153117521Snjl * FUNCTION:    AcpiDbCheckTextModeCorruption
154117521Snjl *
155117521Snjl * PARAMETERS:  Table           - Table buffer
156117521Snjl *              TableLength     - Length of table from the table header
157117521Snjl *              FileLength      - Length of the file that contains the table
158117521Snjl *
159117521Snjl * RETURN:      Status
160117521Snjl *
161117521Snjl * DESCRIPTION: Check table for text mode file corruption where all linefeed
162117521Snjl *              characters (LF) have been replaced by carriage return linefeed
163117521Snjl *              pairs (CR/LF).
164117521Snjl *
165117521Snjl ******************************************************************************/
166117521Snjl
167117521Snjlstatic ACPI_STATUS
168117521SnjlAcpiDbCheckTextModeCorruption (
169117521Snjl    UINT8                   *Table,
170117521Snjl    UINT32                  TableLength,
171117521Snjl    UINT32                  FileLength)
172117521Snjl{
173117521Snjl    UINT32                  i;
174117521Snjl    UINT32                  Pairs = 0;
175117521Snjl
176117521Snjl
177117521Snjl    if (TableLength != FileLength)
178117521Snjl    {
179167802Sjkim        ACPI_WARNING ((AE_INFO,
180167802Sjkim            "File length (0x%X) is not the same as the table length (0x%X)",
181151937Sjkim            FileLength, TableLength));
182117521Snjl    }
183117521Snjl
184117521Snjl    /* Scan entire table to determine if each LF has been prefixed with a CR */
185117521Snjl
186117521Snjl    for (i = 1; i < FileLength; i++)
187117521Snjl    {
188117521Snjl        if (Table[i] == 0x0A)
189117521Snjl        {
190117521Snjl            if (Table[i - 1] != 0x0D)
191117521Snjl            {
192193267Sjkim                /* The LF does not have a preceding CR, table not corrupted */
193117521Snjl
194117521Snjl                return (AE_OK);
195117521Snjl            }
196117521Snjl            else
197117521Snjl            {
198117521Snjl                /* Found a CR/LF pair */
199117521Snjl
200117521Snjl                Pairs++;
201117521Snjl            }
202117521Snjl            i++;
203117521Snjl        }
204117521Snjl    }
205117521Snjl
206167802Sjkim    if (!Pairs)
207167802Sjkim    {
208167802Sjkim        return (AE_OK);
209167802Sjkim    }
210167802Sjkim
211123315Snjl    /*
212117521Snjl     * Entire table scanned, each CR is part of a CR/LF pair --
213117521Snjl     * meaning that the table was treated as a text file somewhere.
214117521Snjl     *
215117521Snjl     * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the
216123315Snjl     * original table are left untouched by the text conversion process --
217117521Snjl     * meaning that we cannot simply replace CR/LF pairs with LFs.
218117521Snjl     */
219117521Snjl    AcpiOsPrintf ("Table has been corrupted by text mode conversion\n");
220209746Sjkim    AcpiOsPrintf ("All LFs (%u) were changed to CR/LF pairs\n", Pairs);
221117521Snjl    AcpiOsPrintf ("Table cannot be repaired!\n");
222117521Snjl    return (AE_BAD_VALUE);
223117521Snjl}
224117521Snjl
225117521Snjl
226117521Snjl/*******************************************************************************
227117521Snjl *
228114237Snjl * FUNCTION:    AcpiDbReadTable
22967754Smsmith *
23067754Smsmith * PARAMETERS:  fp              - File that contains table
231114237Snjl *              Table           - Return value, buffer with table
232114237Snjl *              TableLength     - Return value, length of table
23367754Smsmith *
23467754Smsmith * RETURN:      Status
23567754Smsmith *
23667754Smsmith * DESCRIPTION: Load the DSDT from the file pointer
23767754Smsmith *
23867754Smsmith ******************************************************************************/
23967754Smsmith
24099679Siwasakistatic ACPI_STATUS
241114237SnjlAcpiDbReadTable (
24267754Smsmith    FILE                    *fp,
243114237Snjl    ACPI_TABLE_HEADER       **Table,
24467754Smsmith    UINT32                  *TableLength)
24567754Smsmith{
24667754Smsmith    ACPI_TABLE_HEADER       TableHeader;
24767754Smsmith    UINT32                  Actual;
24869450Smsmith    ACPI_STATUS             Status;
249117521Snjl    UINT32                  FileSize;
250167802Sjkim    BOOLEAN                 StandardHeader = TRUE;
25167754Smsmith
25267754Smsmith
253167802Sjkim    /* Get the file size */
254167802Sjkim
255117521Snjl    fseek (fp, 0, SEEK_END);
256151937Sjkim    FileSize = (UINT32) ftell (fp);
257117521Snjl    fseek (fp, 0, SEEK_SET);
258117521Snjl
259167802Sjkim    if (FileSize < 4)
26067754Smsmith    {
261151937Sjkim        return (AE_BAD_HEADER);
26267754Smsmith    }
26367754Smsmith
264167802Sjkim    /* Read the signature */
26569450Smsmith
266167802Sjkim    if (fread (&TableHeader, 1, 4, fp) != 4)
26767754Smsmith    {
268167802Sjkim        AcpiOsPrintf ("Could not read the table signature\n");
269167802Sjkim        return (AE_BAD_HEADER);
27067754Smsmith    }
27167754Smsmith
272167802Sjkim    fseek (fp, 0, SEEK_SET);
273151937Sjkim
274167802Sjkim    /* The RSDT and FACS tables do not have standard ACPI headers */
275167802Sjkim
276167802Sjkim    if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD ") ||
277167802Sjkim        ACPI_COMPARE_NAME (TableHeader.Signature, "FACS"))
278151937Sjkim    {
279167802Sjkim        *TableLength = FileSize;
280167802Sjkim        StandardHeader = FALSE;
281151937Sjkim    }
282167802Sjkim    else
283167802Sjkim    {
284193267Sjkim        /* Read the table header */
285151937Sjkim
286167802Sjkim        if (fread (&TableHeader, 1, sizeof (TableHeader), fp) !=
287167802Sjkim                sizeof (ACPI_TABLE_HEADER))
288167802Sjkim        {
289167802Sjkim            AcpiOsPrintf ("Could not read the table header\n");
290167802Sjkim            return (AE_BAD_HEADER);
291167802Sjkim        }
29269450Smsmith
293167802Sjkim#if 0
294167802Sjkim        /* Validate the table header/length */
295167802Sjkim
296167802Sjkim        Status = AcpiTbValidateTableHeader (&TableHeader);
297167802Sjkim        if (ACPI_FAILURE (Status))
298167802Sjkim        {
299167802Sjkim            AcpiOsPrintf ("Table header is invalid!\n");
300167802Sjkim            return (Status);
301167802Sjkim        }
302167802Sjkim#endif
303167802Sjkim
304167802Sjkim        /* File size must be at least as long as the Header-specified length */
305167802Sjkim
306167802Sjkim        if (TableHeader.Length > FileSize)
307167802Sjkim        {
308167802Sjkim            AcpiOsPrintf (
309167802Sjkim                "TableHeader length [0x%X] greater than the input file size [0x%X]\n",
310167802Sjkim                TableHeader.Length, FileSize);
311167802Sjkim            return (AE_BAD_HEADER);
312167802Sjkim        }
313167802Sjkim
314167802Sjkim#ifdef ACPI_OBSOLETE_CODE
315167802Sjkim        /* We only support a limited number of table types */
316167802Sjkim
317167802Sjkim        if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) &&
318167802Sjkim            ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) &&
319167802Sjkim            ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4))
320167802Sjkim        {
321167802Sjkim            AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n",
322167802Sjkim                (char *) TableHeader.Signature);
323167802Sjkim            ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
324167802Sjkim            return (AE_ERROR);
325167802Sjkim        }
326167802Sjkim#endif
327167802Sjkim
328167802Sjkim        *TableLength = TableHeader.Length;
32969450Smsmith    }
33069450Smsmith
33167754Smsmith    /* Allocate a buffer for the table */
33267754Smsmith
333167802Sjkim    *Table = AcpiOsAllocate ((size_t) FileSize);
334114237Snjl    if (!*Table)
33567754Smsmith    {
336151937Sjkim        AcpiOsPrintf (
337151937Sjkim            "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
338167802Sjkim            TableHeader.Signature, *TableLength);
33967754Smsmith        return (AE_NO_MEMORY);
34067754Smsmith    }
34167754Smsmith
34267754Smsmith    /* Get the rest of the table */
34367754Smsmith
344117521Snjl    fseek (fp, 0, SEEK_SET);
345117521Snjl    Actual = fread (*Table, 1, (size_t) FileSize, fp);
346117521Snjl    if (Actual == FileSize)
34767754Smsmith    {
348167802Sjkim        if (StandardHeader)
349167802Sjkim        {
350167802Sjkim            /* Now validate the checksum */
351107325Siwasaki
352202771Sjkim            Status = AcpiTbVerifyChecksum ((void *) *Table,
353167802Sjkim                        ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length);
354117521Snjl
355167802Sjkim            if (Status == AE_BAD_CHECKSUM)
356167802Sjkim            {
357167802Sjkim                Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table,
358167802Sjkim                            FileSize, (*Table)->Length);
359167802Sjkim                return (Status);
360167802Sjkim            }
361117521Snjl        }
36267754Smsmith        return (AE_OK);
36367754Smsmith    }
36467754Smsmith
36567754Smsmith    if (Actual > 0)
36667754Smsmith    {
367117521Snjl        AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n",
368117521Snjl            FileSize, Actual);
36984491Smsmith        return (AE_OK);
37067754Smsmith    }
37167754Smsmith
37267754Smsmith    AcpiOsPrintf ("Error - could not read the table file\n");
373114237Snjl    AcpiOsFree (*Table);
374114237Snjl    *Table = NULL;
37567754Smsmith    *TableLength = 0;
37667754Smsmith
37767754Smsmith    return (AE_ERROR);
37867754Smsmith}
37967754Smsmith
38067754Smsmith
38167754Smsmith/*******************************************************************************
38267754Smsmith *
38367754Smsmith * FUNCTION:    AeLocalLoadTable
38467754Smsmith *
385114237Snjl * PARAMETERS:  Table           - pointer to a buffer containing the entire
38667754Smsmith *                                table to be loaded
38767754Smsmith *
38867754Smsmith * RETURN:      Status
38967754Smsmith *
39067754Smsmith * DESCRIPTION: This function is called to load a table from the caller's
391193267Sjkim *              buffer. The buffer must contain an entire ACPI Table including
392193267Sjkim *              a valid header. The header fields will be verified, and if it
39367754Smsmith *              is determined that the table is invalid, the call will fail.
39467754Smsmith *
39567754Smsmith ******************************************************************************/
39667754Smsmith
397151937Sjkimstatic ACPI_STATUS
39867754SmsmithAeLocalLoadTable (
399114237Snjl    ACPI_TABLE_HEADER       *Table)
40067754Smsmith{
401167802Sjkim    ACPI_STATUS             Status = AE_OK;
402167802Sjkim/*    ACPI_TABLE_DESC         TableInfo; */
40367754Smsmith
40467754Smsmith
405167802Sjkim    ACPI_FUNCTION_TRACE (AeLocalLoadTable);
406167802Sjkim#if 0
40767754Smsmith
408114237Snjl
409114237Snjl    if (!Table)
41067754Smsmith    {
41167754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
41267754Smsmith    }
41367754Smsmith
414114237Snjl    TableInfo.Pointer = Table;
415114237Snjl    Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL);
416100966Siwasaki    if (ACPI_FAILURE (Status))
417100966Siwasaki    {
418100966Siwasaki        return_ACPI_STATUS (Status);
419100966Siwasaki    }
420100966Siwasaki
42167754Smsmith    /* Install the new table into the local data structures */
42267754Smsmith
42399679Siwasaki    Status = AcpiTbInstallTable (&TableInfo);
42467754Smsmith    if (ACPI_FAILURE (Status))
42567754Smsmith    {
426151937Sjkim        if (Status == AE_ALREADY_EXISTS)
427151937Sjkim        {
428151937Sjkim            /* Table already exists, no error */
429151937Sjkim
430151937Sjkim            Status = AE_OK;
431151937Sjkim        }
432151937Sjkim
43367754Smsmith        /* Free table allocated by AcpiTbGetTable */
43467754Smsmith
43567754Smsmith        AcpiTbDeleteSingleTable (&TableInfo);
43667754Smsmith        return_ACPI_STATUS (Status);
43767754Smsmith    }
43867754Smsmith
439114237Snjl#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
44067754Smsmith
44167754Smsmith    Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
44267754Smsmith    if (ACPI_FAILURE (Status))
44367754Smsmith    {
44467754Smsmith        /* Uninstall table and free the buffer */
44567754Smsmith
446167802Sjkim        AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT);
44767754Smsmith        return_ACPI_STATUS (Status);
44867754Smsmith    }
44967754Smsmith#endif
450167802Sjkim#endif
45167754Smsmith
45267754Smsmith    return_ACPI_STATUS (Status);
45367754Smsmith}
45467754Smsmith
45567754Smsmith
456107325Siwasaki/*******************************************************************************
457107325Siwasaki *
458114237Snjl * FUNCTION:    AcpiDbReadTableFromFile
459107325Siwasaki *
460114237Snjl * PARAMETERS:  Filename         - File where table is located
461114237Snjl *              Table            - Where a pointer to the table is returned
462107325Siwasaki *
463107325Siwasaki * RETURN:      Status
464107325Siwasaki *
465107325Siwasaki * DESCRIPTION: Get an ACPI table from a file
466107325Siwasaki *
467107325Siwasaki ******************************************************************************/
468107325Siwasaki
46967754SmsmithACPI_STATUS
470114237SnjlAcpiDbReadTableFromFile (
471114237Snjl    char                    *Filename,
472114237Snjl    ACPI_TABLE_HEADER       **Table)
47367754Smsmith{
47467754Smsmith    FILE                    *fp;
47599146Siwasaki    UINT32                  TableLength;
47667754Smsmith    ACPI_STATUS             Status;
47767754Smsmith
478107325Siwasaki
47967754Smsmith    /* Open the file */
48067754Smsmith
48167754Smsmith    fp = fopen (Filename, "rb");
48267754Smsmith    if (!fp)
48367754Smsmith    {
484114237Snjl        AcpiOsPrintf ("Could not open input file %s\n", Filename);
48567754Smsmith        return (AE_ERROR);
48667754Smsmith    }
48767754Smsmith
48867754Smsmith    /* Get the entire file */
48967754Smsmith
490100966Siwasaki    fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
491114237Snjl    Status = AcpiDbReadTable (fp, Table, &TableLength);
49267754Smsmith    fclose(fp);
49367754Smsmith
49467754Smsmith    if (ACPI_FAILURE (Status))
49567754Smsmith    {
496151937Sjkim        AcpiOsPrintf ("Could not get table from the file\n");
49767754Smsmith        return (Status);
49867754Smsmith    }
49967754Smsmith
50099146Siwasaki    return (AE_OK);
50199146Siwasaki }
50299146Siwasaki#endif
50367754Smsmith
504107325Siwasaki
50599146Siwasaki/*******************************************************************************
50699146Siwasaki *
507114237Snjl * FUNCTION:    AcpiDbGetTableFromFile
50899146Siwasaki *
509151937Sjkim * PARAMETERS:  Filename        - File where table is located
510151937Sjkim *              ReturnTable     - Where a pointer to the table is returned
51199146Siwasaki *
51299146Siwasaki * RETURN:      Status
51399146Siwasaki *
51499146Siwasaki * DESCRIPTION: Load an ACPI table from a file
51599146Siwasaki *
51699146Siwasaki ******************************************************************************/
51799146Siwasaki
51899146SiwasakiACPI_STATUS
519114237SnjlAcpiDbGetTableFromFile (
520114237Snjl    char                    *Filename,
521114237Snjl    ACPI_TABLE_HEADER       **ReturnTable)
52299146Siwasaki{
52399146Siwasaki#ifdef ACPI_APPLICATION
52499146Siwasaki    ACPI_STATUS             Status;
525114237Snjl    ACPI_TABLE_HEADER       *Table;
526167802Sjkim    BOOLEAN                 IsAmlTable = TRUE;
52799146Siwasaki
52899146Siwasaki
529114237Snjl    Status = AcpiDbReadTableFromFile (Filename, &Table);
53099146Siwasaki    if (ACPI_FAILURE (Status))
53199146Siwasaki    {
53299146Siwasaki        return (Status);
53399146Siwasaki    }
53499146Siwasaki
535167802Sjkim#ifdef ACPI_DATA_TABLE_DISASSEMBLY
536167802Sjkim    IsAmlTable = AcpiUtIsAmlTable (Table);
537167802Sjkim#endif
53899146Siwasaki
539167802Sjkim    if (IsAmlTable)
54067754Smsmith    {
541167802Sjkim        /* Attempt to recognize and install the table */
542167802Sjkim
543167802Sjkim        Status = AeLocalLoadTable (Table);
544167802Sjkim        if (ACPI_FAILURE (Status))
54567754Smsmith        {
546167802Sjkim            if (Status == AE_ALREADY_EXISTS)
547167802Sjkim            {
548167802Sjkim                AcpiOsPrintf ("Table %4.4s is already installed\n",
549167802Sjkim                    Table->Signature);
550167802Sjkim            }
551167802Sjkim            else
552167802Sjkim            {
553167802Sjkim                AcpiOsPrintf ("Could not install table, %s\n",
554167802Sjkim                    AcpiFormatException (Status));
555167802Sjkim            }
556167802Sjkim
557167802Sjkim            return (Status);
55867754Smsmith        }
55980062Smsmith
560167802Sjkim        fprintf (stderr,
561167802Sjkim            "Acpi table [%4.4s] successfully installed and loaded\n",
562167802Sjkim            Table->Signature);
56367754Smsmith    }
56467754Smsmith
56567754Smsmith    AcpiGbl_AcpiHardwarePresent = FALSE;
566114237Snjl    if (ReturnTable)
567114237Snjl    {
568114237Snjl        *ReturnTable = Table;
569114237Snjl    }
57067754Smsmith
571114237Snjl
57267754Smsmith#endif  /* ACPI_APPLICATION */
57367754Smsmith    return (AE_OK);
57467754Smsmith}
57567754Smsmith
576102550Siwasaki#endif  /* ACPI_DEBUGGER */
57767754Smsmith
578