dbfileio.c revision 151600
167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: dbfileio - Debugger file I/O commands.  These can't usually
467754Smsmith *              be used when running the debugger in Ring 0 (Kernel mode)
5126372Snjl *              $Revision: 76 $
667754Smsmith *
767754Smsmith ******************************************************************************/
867754Smsmith
967754Smsmith/******************************************************************************
1067754Smsmith *
1167754Smsmith * 1. Copyright Notice
1267754Smsmith *
13126372Snjl * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
1470243Smsmith * All rights reserved.
1567754Smsmith *
1667754Smsmith * 2. License
1767754Smsmith *
1867754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1967754Smsmith * rights.  You may have additional license terms from the party that provided
2067754Smsmith * you this software, covering your right to use that party's intellectual
2167754Smsmith * property rights.
2267754Smsmith *
2367754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2467754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2567754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2667754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2767754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2867754Smsmith * Code in any form, with the right to sublicense such rights; and
2967754Smsmith *
3067754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3167754Smsmith * license (with the right to sublicense), under only those claims of Intel
3267754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3367754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3467754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3567754Smsmith * license, and in no event shall the patent license extend to any additions
3667754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3767754Smsmith * is granted directly or by implication, estoppel or otherwise;
3867754Smsmith *
3967754Smsmith * The above copyright and patent license is granted only if the following
4067754Smsmith * conditions are met:
4167754Smsmith *
4267754Smsmith * 3. Conditions
4367754Smsmith *
4467754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4567754Smsmith * Redistribution of source code of any substantial portion of the Covered
4667754Smsmith * Code or modification with rights to further distribute source must include
4767754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4867754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4967754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
5067754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5167754Smsmith * Code and the date of any change.  Licensee must include in that file the
5267754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5367754Smsmith * must include a prominent statement that the modification is derived,
5467754Smsmith * directly or indirectly, from Original Intel Code.
5567754Smsmith *
5667754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5767754Smsmith * Redistribution of source code of any substantial portion of the Covered
5867754Smsmith * Code or modification without rights to further distribute source must
5967754Smsmith * include the following Disclaimer and Export Compliance provision in the
6067754Smsmith * documentation and/or other materials provided with distribution.  In
6167754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6267754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6367754Smsmith * license from Licensee to its licensee is limited to the intellectual
6467754Smsmith * property embodied in the software Licensee provides to its licensee, and
6567754Smsmith * not to intellectual property embodied in modifications its licensee may
6667754Smsmith * make.
6767754Smsmith *
6867754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6967754Smsmith * substantial portion of the Covered Code or modification must reproduce the
7067754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7167754Smsmith * provision in the documentation and/or other materials provided with the
7267754Smsmith * distribution.
7367754Smsmith *
7467754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7567754Smsmith * Intel Code.
7667754Smsmith *
7767754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7867754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7967754Smsmith * other dealings in products derived from or relating to the Covered Code
8067754Smsmith * without prior written authorization from Intel.
8167754Smsmith *
8267754Smsmith * 4. Disclaimer and Export Compliance
8367754Smsmith *
8467754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8567754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8667754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8767754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8867754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8967754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
9067754Smsmith * PARTICULAR PURPOSE.
9167754Smsmith *
9267754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9367754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9467754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9567754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9667754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9767754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9867754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9967754Smsmith * LIMITED REMEDY.
10067754Smsmith *
10167754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10267754Smsmith * software or system incorporating such software without first obtaining any
10367754Smsmith * required license or other approval from the U. S. Department of Commerce or
10467754Smsmith * any other agency or department of the United States Government.  In the
10567754Smsmith * event Licensee exports any such software from the United States or
10667754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10767754Smsmith * ensure that the distribution and export/re-export of the software is in
10867754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10967754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
11067754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11167754Smsmith * software, or service, directly or indirectly, to any country for which the
11267754Smsmith * United States government or any agency thereof requires an export license,
11367754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11467754Smsmith * such license, approval or letter.
11567754Smsmith *
11667754Smsmith *****************************************************************************/
11767754Smsmith
11867754Smsmith
119151600Sobrien#include <contrib/dev/acpica/acpi.h>
120151600Sobrien#include <contrib/dev/acpica/acdebug.h>
121151600Sobrien#include <contrib/dev/acpica/acnamesp.h>
122151600Sobrien#include <contrib/dev/acpica/actables.h>
12367754Smsmith
124102550Siwasaki#if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
12567754Smsmith
126102550Siwasaki#define _COMPONENT          ACPI_CA_DEBUGGER
12791116Smsmith        ACPI_MODULE_NAME    ("dbfileio")
12867754Smsmith
12967754Smsmith
13084491Smsmith/*
13184491Smsmith * NOTE: this is here for lack of a better place.  It is used in all
13284491Smsmith * flavors of the debugger, need LCD file
13384491Smsmith */
13467754Smsmith#ifdef ACPI_APPLICATION
13567754Smsmith#include <stdio.h>
13683174SmsmithFILE                        *AcpiGbl_DebugFile = NULL;
13767754Smsmith#endif
13867754Smsmith
13967754Smsmith
140102550Siwasaki#ifdef ACPI_DEBUGGER
14167754Smsmith/*******************************************************************************
14267754Smsmith *
14367754Smsmith * FUNCTION:    AcpiDbCloseDebugFile
14467754Smsmith *
14567754Smsmith * PARAMETERS:  None
14667754Smsmith *
14767754Smsmith * RETURN:      Status
14867754Smsmith *
14967754Smsmith * DESCRIPTION: If open, close the current debug output file
15067754Smsmith *
15167754Smsmith ******************************************************************************/
15267754Smsmith
15367754Smsmithvoid
15467754SmsmithAcpiDbCloseDebugFile (
15567754Smsmith    void)
15667754Smsmith{
15767754Smsmith
15867754Smsmith#ifdef ACPI_APPLICATION
15967754Smsmith
16083174Smsmith    if (AcpiGbl_DebugFile)
16167754Smsmith    {
16283174Smsmith       fclose (AcpiGbl_DebugFile);
16383174Smsmith       AcpiGbl_DebugFile = NULL;
16483174Smsmith       AcpiGbl_DbOutputToFile = FALSE;
16583174Smsmith       AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename);
16667754Smsmith    }
16767754Smsmith#endif
16867754Smsmith}
16967754Smsmith
17067754Smsmith
17167754Smsmith/*******************************************************************************
17267754Smsmith *
17367754Smsmith * FUNCTION:    AcpiDbOpenDebugFile
17467754Smsmith *
17567754Smsmith * PARAMETERS:  Name                - Filename to open
17667754Smsmith *
17767754Smsmith * RETURN:      Status
17867754Smsmith *
17967754Smsmith * DESCRIPTION: Open a file where debug output will be directed.
18067754Smsmith *
18167754Smsmith ******************************************************************************/
18267754Smsmith
18367754Smsmithvoid
18467754SmsmithAcpiDbOpenDebugFile (
185114237Snjl    char                    *Name)
18667754Smsmith{
18767754Smsmith
18867754Smsmith#ifdef ACPI_APPLICATION
18967754Smsmith
19067754Smsmith    AcpiDbCloseDebugFile ();
19183174Smsmith    AcpiGbl_DebugFile = fopen (Name, "w+");
19283174Smsmith    if (AcpiGbl_DebugFile)
19367754Smsmith    {
19467754Smsmith        AcpiOsPrintf ("Debug output file %s opened\n", Name);
19591116Smsmith        ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name);
19683174Smsmith        AcpiGbl_DbOutputToFile = TRUE;
19767754Smsmith    }
19873561Smsmith    else
19973561Smsmith    {
20073561Smsmith        AcpiOsPrintf ("Could not open debug file %s\n", Name);
20173561Smsmith    }
20267754Smsmith
20367754Smsmith#endif
20467754Smsmith}
205100966Siwasaki#endif
20667754Smsmith
20767754Smsmith
20867754Smsmith#ifdef ACPI_APPLICATION
209117521Snjl
21067754Smsmith/*******************************************************************************
21167754Smsmith *
212117521Snjl * FUNCTION:    AcpiDbCheckTextModeCorruption
213117521Snjl *
214117521Snjl * PARAMETERS:  Table           - Table buffer
215117521Snjl *              TableLength     - Length of table from the table header
216117521Snjl *              FileLength      - Length of the file that contains the table
217117521Snjl *
218117521Snjl * RETURN:      Status
219117521Snjl *
220117521Snjl * DESCRIPTION: Check table for text mode file corruption where all linefeed
221117521Snjl *              characters (LF) have been replaced by carriage return linefeed
222117521Snjl *              pairs (CR/LF).
223117521Snjl *
224117521Snjl ******************************************************************************/
225117521Snjl
226117521Snjlstatic ACPI_STATUS
227117521SnjlAcpiDbCheckTextModeCorruption (
228117521Snjl    UINT8                   *Table,
229117521Snjl    UINT32                  TableLength,
230117521Snjl    UINT32                  FileLength)
231117521Snjl{
232117521Snjl    UINT32                  i;
233117521Snjl    UINT32                  Pairs = 0;
234117521Snjl
235117521Snjl
236117521Snjl    if (TableLength != FileLength)
237117521Snjl    {
238117521Snjl        ACPI_REPORT_WARNING (("File length (0x%X) is not the same as the table length (0x%X)\n",
239117521Snjl                FileLength, TableLength));
240117521Snjl    }
241117521Snjl
242117521Snjl    /* Scan entire table to determine if each LF has been prefixed with a CR */
243117521Snjl
244117521Snjl    for (i = 1; i < FileLength; i++)
245117521Snjl    {
246117521Snjl        if (Table[i] == 0x0A)
247117521Snjl        {
248117521Snjl            if (Table[i - 1] != 0x0D)
249117521Snjl            {
250117521Snjl                /* the LF does not have a preceeding CR, table is not corrupted */
251117521Snjl
252117521Snjl                return (AE_OK);
253117521Snjl            }
254117521Snjl            else
255117521Snjl            {
256117521Snjl                /* Found a CR/LF pair */
257117521Snjl
258117521Snjl                Pairs++;
259117521Snjl            }
260117521Snjl            i++;
261117521Snjl        }
262117521Snjl    }
263117521Snjl
264123315Snjl    /*
265117521Snjl     * Entire table scanned, each CR is part of a CR/LF pair --
266117521Snjl     * meaning that the table was treated as a text file somewhere.
267117521Snjl     *
268117521Snjl     * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the
269123315Snjl     * original table are left untouched by the text conversion process --
270117521Snjl     * meaning that we cannot simply replace CR/LF pairs with LFs.
271117521Snjl     */
272117521Snjl    AcpiOsPrintf ("Table has been corrupted by text mode conversion\n");
273117521Snjl    AcpiOsPrintf ("All LFs (%d) were changed to CR/LF pairs\n", Pairs);
274117521Snjl    AcpiOsPrintf ("Table cannot be repaired!\n");
275117521Snjl    return (AE_BAD_VALUE);
276117521Snjl}
277117521Snjl
278117521Snjl
279117521Snjl/*******************************************************************************
280117521Snjl *
281114237Snjl * FUNCTION:    AcpiDbReadTable
28267754Smsmith *
28367754Smsmith * PARAMETERS:  fp              - File that contains table
284114237Snjl *              Table           - Return value, buffer with table
285114237Snjl *              TableLength     - Return value, length of table
28667754Smsmith *
28767754Smsmith * RETURN:      Status
28867754Smsmith *
28967754Smsmith * DESCRIPTION: Load the DSDT from the file pointer
29067754Smsmith *
29167754Smsmith ******************************************************************************/
29267754Smsmith
29399679Siwasakistatic ACPI_STATUS
294114237SnjlAcpiDbReadTable (
29567754Smsmith    FILE                    *fp,
296114237Snjl    ACPI_TABLE_HEADER       **Table,
29767754Smsmith    UINT32                  *TableLength)
29867754Smsmith{
29967754Smsmith    ACPI_TABLE_HEADER       TableHeader;
30067754Smsmith    UINT32                  Actual;
30169450Smsmith    ACPI_STATUS             Status;
302117521Snjl    UINT32                  FileSize;
30367754Smsmith
30467754Smsmith
305117521Snjl    fseek (fp, 0, SEEK_END);
306117521Snjl    FileSize = ftell (fp);
307117521Snjl    fseek (fp, 0, SEEK_SET);
308117521Snjl
30967754Smsmith    /* Read the table header */
31067754Smsmith
31169450Smsmith    if (fread (&TableHeader, 1, sizeof (TableHeader), fp) != sizeof (ACPI_TABLE_HEADER))
31267754Smsmith    {
31367754Smsmith        AcpiOsPrintf ("Couldn't read the table header\n");
31467754Smsmith        return (AE_BAD_SIGNATURE);
31567754Smsmith    }
31667754Smsmith
31769450Smsmith    /* Validate the table header/length */
31869450Smsmith
31969450Smsmith    Status = AcpiTbValidateTableHeader (&TableHeader);
32069450Smsmith    if ((ACPI_FAILURE (Status)) ||
321100966Siwasaki        (TableHeader.Length > 0x800000))  /* 8 Mbyte should be enough */
32267754Smsmith    {
32369450Smsmith        AcpiOsPrintf ("Table header is invalid!\n");
32467754Smsmith        return (AE_ERROR);
32567754Smsmith    }
32667754Smsmith
32769450Smsmith    /* We only support a limited number of table types */
32869450Smsmith
32991116Smsmith    if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) &&
33091116Smsmith        ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) &&
33191116Smsmith        ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4))
33269450Smsmith    {
33369450Smsmith        AcpiOsPrintf ("Table signature is invalid\n");
33491116Smsmith        ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
33569450Smsmith        return (AE_ERROR);
33669450Smsmith    }
33769450Smsmith
33867754Smsmith    /* Allocate a buffer for the table */
33967754Smsmith
34069450Smsmith    *TableLength = TableHeader.Length;
341117521Snjl    *Table = AcpiOsAllocate ((size_t) (FileSize));
342114237Snjl    if (!*Table)
34367754Smsmith    {
34483174Smsmith        AcpiOsPrintf ("Could not allocate memory for ACPI table %4.4s (size=%X)\n",
34582367Smsmith                    TableHeader.Signature, TableHeader.Length);
34667754Smsmith        return (AE_NO_MEMORY);
34767754Smsmith    }
34867754Smsmith
34967754Smsmith    /* Get the rest of the table */
35067754Smsmith
351117521Snjl    fseek (fp, 0, SEEK_SET);
352117521Snjl    Actual = fread (*Table, 1, (size_t) FileSize, fp);
353117521Snjl    if (Actual == FileSize)
35467754Smsmith    {
355107325Siwasaki        /* Now validate the checksum */
356107325Siwasaki
357114237Snjl        Status = AcpiTbVerifyTableChecksum (*Table);
358117521Snjl
359117521Snjl        if (Status == AE_BAD_CHECKSUM)
360117521Snjl        {
361123315Snjl            Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table,
362117521Snjl                        FileSize, (*Table)->Length);
363117521Snjl            return (Status);
364117521Snjl        }
36567754Smsmith        return (AE_OK);
36667754Smsmith    }
36767754Smsmith
36867754Smsmith    if (Actual > 0)
36967754Smsmith    {
370117521Snjl        AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n",
371117521Snjl            FileSize, Actual);
37284491Smsmith        return (AE_OK);
37367754Smsmith    }
37467754Smsmith
37567754Smsmith    AcpiOsPrintf ("Error - could not read the table file\n");
376114237Snjl    AcpiOsFree (*Table);
377114237Snjl    *Table = NULL;
37867754Smsmith    *TableLength = 0;
37967754Smsmith
38067754Smsmith    return (AE_ERROR);
38167754Smsmith}
38267754Smsmith#endif
38367754Smsmith
38467754Smsmith
38567754Smsmith/*******************************************************************************
38667754Smsmith *
38767754Smsmith * FUNCTION:    AeLocalLoadTable
38867754Smsmith *
389114237Snjl * PARAMETERS:  Table           - pointer to a buffer containing the entire
39067754Smsmith *                                table to be loaded
39167754Smsmith *
39267754Smsmith * RETURN:      Status
39367754Smsmith *
39467754Smsmith * DESCRIPTION: This function is called to load a table from the caller's
39567754Smsmith *              buffer.  The buffer must contain an entire ACPI Table including
39667754Smsmith *              a valid header.  The header fields will be verified, and if it
39767754Smsmith *              is determined that the table is invalid, the call will fail.
39867754Smsmith *
39967754Smsmith ******************************************************************************/
40067754Smsmith
40167754SmsmithACPI_STATUS
40267754SmsmithAeLocalLoadTable (
403114237Snjl    ACPI_TABLE_HEADER       *Table)
40467754Smsmith{
40567754Smsmith    ACPI_STATUS             Status;
40667754Smsmith    ACPI_TABLE_DESC         TableInfo;
40767754Smsmith
40867754Smsmith
40991116Smsmith    ACPI_FUNCTION_TRACE ("AeLocalLoadTable");
41067754Smsmith
411114237Snjl
412114237Snjl    if (!Table)
41367754Smsmith    {
41467754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
41567754Smsmith    }
41667754Smsmith
417114237Snjl    TableInfo.Pointer = Table;
418114237Snjl    Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL);
419100966Siwasaki    if (ACPI_FAILURE (Status))
420100966Siwasaki    {
421100966Siwasaki        return_ACPI_STATUS (Status);
422100966Siwasaki    }
423100966Siwasaki
42467754Smsmith    /* Install the new table into the local data structures */
42567754Smsmith
42699679Siwasaki    Status = AcpiTbInstallTable (&TableInfo);
42767754Smsmith    if (ACPI_FAILURE (Status))
42867754Smsmith    {
42967754Smsmith        /* Free table allocated by AcpiTbGetTable */
43067754Smsmith
43167754Smsmith        AcpiTbDeleteSingleTable (&TableInfo);
43267754Smsmith        return_ACPI_STATUS (Status);
43367754Smsmith    }
43467754Smsmith
435114237Snjl#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
43667754Smsmith
43767754Smsmith    Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
43867754Smsmith    if (ACPI_FAILURE (Status))
43967754Smsmith    {
44067754Smsmith        /* Uninstall table and free the buffer */
44167754Smsmith
442117521Snjl        AcpiTbDeleteTablesByType (ACPI_TABLE_DSDT);
44367754Smsmith        return_ACPI_STATUS (Status);
44467754Smsmith    }
44567754Smsmith#endif
44667754Smsmith
44767754Smsmith    return_ACPI_STATUS (Status);
44867754Smsmith}
44967754Smsmith
45067754Smsmith
45199146Siwasaki#ifdef ACPI_APPLICATION
452107325Siwasaki/*******************************************************************************
453107325Siwasaki *
454114237Snjl * FUNCTION:    AcpiDbReadTableFromFile
455107325Siwasaki *
456114237Snjl * PARAMETERS:  Filename         - File where table is located
457114237Snjl *              Table            - Where a pointer to the table is returned
458107325Siwasaki *
459107325Siwasaki * RETURN:      Status
460107325Siwasaki *
461107325Siwasaki * DESCRIPTION: Get an ACPI table from a file
462107325Siwasaki *
463107325Siwasaki ******************************************************************************/
464107325Siwasaki
46567754SmsmithACPI_STATUS
466114237SnjlAcpiDbReadTableFromFile (
467114237Snjl    char                    *Filename,
468114237Snjl    ACPI_TABLE_HEADER       **Table)
46967754Smsmith{
47067754Smsmith    FILE                    *fp;
47199146Siwasaki    UINT32                  TableLength;
47267754Smsmith    ACPI_STATUS             Status;
47367754Smsmith
474107325Siwasaki
47567754Smsmith    /* Open the file */
47667754Smsmith
47767754Smsmith    fp = fopen (Filename, "rb");
47867754Smsmith    if (!fp)
47967754Smsmith    {
480114237Snjl        AcpiOsPrintf ("Could not open input file %s\n", Filename);
48167754Smsmith        return (AE_ERROR);
48267754Smsmith    }
48367754Smsmith
48467754Smsmith    /* Get the entire file */
48567754Smsmith
486100966Siwasaki    fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
487114237Snjl    Status = AcpiDbReadTable (fp, Table, &TableLength);
48867754Smsmith    fclose(fp);
48967754Smsmith
49067754Smsmith    if (ACPI_FAILURE (Status))
49167754Smsmith    {
49267754Smsmith        AcpiOsPrintf ("Couldn't get table from the file\n");
49367754Smsmith        return (Status);
49467754Smsmith    }
49567754Smsmith
49699146Siwasaki    return (AE_OK);
49799146Siwasaki }
49899146Siwasaki#endif
49967754Smsmith
500107325Siwasaki
50199146Siwasaki/*******************************************************************************
50299146Siwasaki *
503114237Snjl * FUNCTION:    AcpiDbGetTableFromFile
50499146Siwasaki *
505114237Snjl * PARAMETERS:  Filename         - File where table is located
506114237Snjl *              Table            - Where a pointer to the table is returned
50799146Siwasaki *
50899146Siwasaki * RETURN:      Status
50999146Siwasaki *
51099146Siwasaki * DESCRIPTION: Load an ACPI table from a file
51199146Siwasaki *
51299146Siwasaki ******************************************************************************/
51399146Siwasaki
51499146SiwasakiACPI_STATUS
515114237SnjlAcpiDbGetTableFromFile (
516114237Snjl    char                    *Filename,
517114237Snjl    ACPI_TABLE_HEADER       **ReturnTable)
51899146Siwasaki{
51999146Siwasaki#ifdef ACPI_APPLICATION
52099146Siwasaki    ACPI_STATUS             Status;
521114237Snjl    ACPI_TABLE_HEADER       *Table;
52299146Siwasaki
52399146Siwasaki
524114237Snjl    Status = AcpiDbReadTableFromFile (Filename, &Table);
52599146Siwasaki    if (ACPI_FAILURE (Status))
52699146Siwasaki    {
52799146Siwasaki        return (Status);
52899146Siwasaki    }
52999146Siwasaki
53099146Siwasaki   /* Attempt to recognize and install the table */
53199146Siwasaki
532114237Snjl    Status = AeLocalLoadTable (Table);
53367754Smsmith    if (ACPI_FAILURE (Status))
53467754Smsmith    {
53587031Smsmith        if (Status == AE_ALREADY_EXISTS)
53667754Smsmith        {
53767754Smsmith            AcpiOsPrintf ("Table %4.4s is already installed\n",
538114237Snjl                            Table->Signature);
53967754Smsmith        }
54067754Smsmith        else
54167754Smsmith        {
54267754Smsmith            AcpiOsPrintf ("Could not install table, %s\n",
54380062Smsmith                            AcpiFormatException (Status));
54467754Smsmith        }
54580062Smsmith
54667754Smsmith        return (Status);
54767754Smsmith    }
54867754Smsmith
549100966Siwasaki    fprintf (stderr, "Acpi table [%4.4s] successfully installed and loaded\n",
550114237Snjl                                Table->Signature);
55167754Smsmith
55267754Smsmith    AcpiGbl_AcpiHardwarePresent = FALSE;
553114237Snjl    if (ReturnTable)
554114237Snjl    {
555114237Snjl        *ReturnTable = Table;
556114237Snjl    }
55767754Smsmith
558114237Snjl
55967754Smsmith#endif  /* ACPI_APPLICATION */
56067754Smsmith    return (AE_OK);
56167754Smsmith}
56267754Smsmith
563102550Siwasaki#endif  /* ACPI_DEBUGGER */
56467754Smsmith
565