dbfileio.c revision 209746
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
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
12202771Sjkim * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
1370243Smsmith * All rights reserved.
1467754Smsmith *
1567754Smsmith * 2. License
1667754Smsmith *
1767754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1867754Smsmith * rights.  You may have additional license terms from the party that provided
1967754Smsmith * you this software, covering your right to use that party's intellectual
2067754Smsmith * property rights.
2167754Smsmith *
2267754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2367754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2467754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2567754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2667754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2767754Smsmith * Code in any form, with the right to sublicense such rights; and
2867754Smsmith *
2967754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3067754Smsmith * license (with the right to sublicense), under only those claims of Intel
3167754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3267754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3367754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3467754Smsmith * license, and in no event shall the patent license extend to any additions
3567754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3667754Smsmith * is granted directly or by implication, estoppel or otherwise;
3767754Smsmith *
3867754Smsmith * The above copyright and patent license is granted only if the following
3967754Smsmith * conditions are met:
4067754Smsmith *
4167754Smsmith * 3. Conditions
4267754Smsmith *
4367754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4467754Smsmith * Redistribution of source code of any substantial portion of the Covered
4567754Smsmith * Code or modification with rights to further distribute source must include
4667754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4767754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4867754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
4967754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5067754Smsmith * Code and the date of any change.  Licensee must include in that file the
5167754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5267754Smsmith * must include a prominent statement that the modification is derived,
5367754Smsmith * directly or indirectly, from Original Intel Code.
5467754Smsmith *
5567754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5667754Smsmith * Redistribution of source code of any substantial portion of the Covered
5767754Smsmith * Code or modification without rights to further distribute source must
5867754Smsmith * include the following Disclaimer and Export Compliance provision in the
5967754Smsmith * documentation and/or other materials provided with distribution.  In
6067754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6167754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6267754Smsmith * license from Licensee to its licensee is limited to the intellectual
6367754Smsmith * property embodied in the software Licensee provides to its licensee, and
6467754Smsmith * not to intellectual property embodied in modifications its licensee may
6567754Smsmith * make.
6667754Smsmith *
6767754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6867754Smsmith * substantial portion of the Covered Code or modification must reproduce the
6967754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7067754Smsmith * provision in the documentation and/or other materials provided with the
7167754Smsmith * distribution.
7267754Smsmith *
7367754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7467754Smsmith * Intel Code.
7567754Smsmith *
7667754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7767754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7867754Smsmith * other dealings in products derived from or relating to the Covered Code
7967754Smsmith * without prior written authorization from Intel.
8067754Smsmith *
8167754Smsmith * 4. Disclaimer and Export Compliance
8267754Smsmith *
8367754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8467754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8567754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8667754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8767754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8867754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8967754Smsmith * PARTICULAR PURPOSE.
9067754Smsmith *
9167754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9267754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9367754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9467754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9567754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9667754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9767754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9867754Smsmith * LIMITED REMEDY.
9967754Smsmith *
10067754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10167754Smsmith * software or system incorporating such software without first obtaining any
10267754Smsmith * required license or other approval from the U. S. Department of Commerce or
10367754Smsmith * any other agency or department of the United States Government.  In the
10467754Smsmith * event Licensee exports any such software from the United States or
10567754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10667754Smsmith * ensure that the distribution and export/re-export of the software is in
10767754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10867754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10967754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11067754Smsmith * software, or service, directly or indirectly, to any country for which the
11167754Smsmith * United States government or any agency thereof requires an export license,
11267754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11367754Smsmith * such license, approval or letter.
11467754Smsmith *
11567754Smsmith *****************************************************************************/
11667754Smsmith
11767754Smsmith
118193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
119193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
120193341Sjkim#include <contrib/dev/acpica/include/acdebug.h>
121193267Sjkim
122193267Sjkim#ifdef ACPI_APPLICATION
123193341Sjkim#include <contrib/dev/acpica/include/actables.h>
124193267Sjkim#endif
12567754Smsmith
126102550Siwasaki#if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
12767754Smsmith
128102550Siwasaki#define _COMPONENT          ACPI_CA_DEBUGGER
12991116Smsmith        ACPI_MODULE_NAME    ("dbfileio")
13067754Smsmith
13184491Smsmith/*
132193267Sjkim * NOTE: this is here for lack of a better place. It is used in all
13384491Smsmith * flavors of the debugger, need LCD file
13484491Smsmith */
13567754Smsmith#ifdef ACPI_APPLICATION
13667754Smsmith#include <stdio.h>
13783174SmsmithFILE                        *AcpiGbl_DebugFile = NULL;
13867754Smsmith#endif
13967754Smsmith
14067754Smsmith
141102550Siwasaki#ifdef ACPI_DEBUGGER
142151937Sjkim
143151937Sjkim/* Local prototypes */
144151937Sjkim
145151940Sjkim#ifdef ACPI_APPLICATION
146151940Sjkim
147151937Sjkimstatic ACPI_STATUS
148151937SjkimAcpiDbCheckTextModeCorruption (
149151937Sjkim    UINT8                   *Table,
150151937Sjkim    UINT32                  TableLength,
151151937Sjkim    UINT32                  FileLength);
152151937Sjkim
153151940Sjkim#endif
154151937Sjkim
15567754Smsmith/*******************************************************************************
15667754Smsmith *
15767754Smsmith * FUNCTION:    AcpiDbCloseDebugFile
15867754Smsmith *
15967754Smsmith * PARAMETERS:  None
16067754Smsmith *
161151937Sjkim * RETURN:      None
16267754Smsmith *
16367754Smsmith * DESCRIPTION: If open, close the current debug output file
16467754Smsmith *
16567754Smsmith ******************************************************************************/
16667754Smsmith
16767754Smsmithvoid
16867754SmsmithAcpiDbCloseDebugFile (
16967754Smsmith    void)
17067754Smsmith{
17167754Smsmith
17267754Smsmith#ifdef ACPI_APPLICATION
17367754Smsmith
17483174Smsmith    if (AcpiGbl_DebugFile)
17567754Smsmith    {
17683174Smsmith       fclose (AcpiGbl_DebugFile);
17783174Smsmith       AcpiGbl_DebugFile = NULL;
17883174Smsmith       AcpiGbl_DbOutputToFile = FALSE;
17983174Smsmith       AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename);
18067754Smsmith    }
18167754Smsmith#endif
18267754Smsmith}
18367754Smsmith
18467754Smsmith
18567754Smsmith/*******************************************************************************
18667754Smsmith *
18767754Smsmith * FUNCTION:    AcpiDbOpenDebugFile
18867754Smsmith *
18967754Smsmith * PARAMETERS:  Name                - Filename to open
19067754Smsmith *
191151937Sjkim * RETURN:      None
19267754Smsmith *
19367754Smsmith * DESCRIPTION: Open a file where debug output will be directed.
19467754Smsmith *
19567754Smsmith ******************************************************************************/
19667754Smsmith
19767754Smsmithvoid
19867754SmsmithAcpiDbOpenDebugFile (
199114237Snjl    char                    *Name)
20067754Smsmith{
20167754Smsmith
20267754Smsmith#ifdef ACPI_APPLICATION
20367754Smsmith
20467754Smsmith    AcpiDbCloseDebugFile ();
20583174Smsmith    AcpiGbl_DebugFile = fopen (Name, "w+");
20683174Smsmith    if (AcpiGbl_DebugFile)
20767754Smsmith    {
20867754Smsmith        AcpiOsPrintf ("Debug output file %s opened\n", Name);
20991116Smsmith        ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name);
21083174Smsmith        AcpiGbl_DbOutputToFile = TRUE;
21167754Smsmith    }
21273561Smsmith    else
21373561Smsmith    {
21473561Smsmith        AcpiOsPrintf ("Could not open debug file %s\n", Name);
21573561Smsmith    }
21667754Smsmith
21767754Smsmith#endif
21867754Smsmith}
219100966Siwasaki#endif
22067754Smsmith
22167754Smsmith
22267754Smsmith#ifdef ACPI_APPLICATION
22367754Smsmith/*******************************************************************************
22467754Smsmith *
225117521Snjl * FUNCTION:    AcpiDbCheckTextModeCorruption
226117521Snjl *
227117521Snjl * PARAMETERS:  Table           - Table buffer
228117521Snjl *              TableLength     - Length of table from the table header
229117521Snjl *              FileLength      - Length of the file that contains the table
230117521Snjl *
231117521Snjl * RETURN:      Status
232117521Snjl *
233117521Snjl * DESCRIPTION: Check table for text mode file corruption where all linefeed
234117521Snjl *              characters (LF) have been replaced by carriage return linefeed
235117521Snjl *              pairs (CR/LF).
236117521Snjl *
237117521Snjl ******************************************************************************/
238117521Snjl
239117521Snjlstatic ACPI_STATUS
240117521SnjlAcpiDbCheckTextModeCorruption (
241117521Snjl    UINT8                   *Table,
242117521Snjl    UINT32                  TableLength,
243117521Snjl    UINT32                  FileLength)
244117521Snjl{
245117521Snjl    UINT32                  i;
246117521Snjl    UINT32                  Pairs = 0;
247117521Snjl
248117521Snjl
249117521Snjl    if (TableLength != FileLength)
250117521Snjl    {
251167802Sjkim        ACPI_WARNING ((AE_INFO,
252167802Sjkim            "File length (0x%X) is not the same as the table length (0x%X)",
253151937Sjkim            FileLength, TableLength));
254117521Snjl    }
255117521Snjl
256117521Snjl    /* Scan entire table to determine if each LF has been prefixed with a CR */
257117521Snjl
258117521Snjl    for (i = 1; i < FileLength; i++)
259117521Snjl    {
260117521Snjl        if (Table[i] == 0x0A)
261117521Snjl        {
262117521Snjl            if (Table[i - 1] != 0x0D)
263117521Snjl            {
264193267Sjkim                /* The LF does not have a preceding CR, table not corrupted */
265117521Snjl
266117521Snjl                return (AE_OK);
267117521Snjl            }
268117521Snjl            else
269117521Snjl            {
270117521Snjl                /* Found a CR/LF pair */
271117521Snjl
272117521Snjl                Pairs++;
273117521Snjl            }
274117521Snjl            i++;
275117521Snjl        }
276117521Snjl    }
277117521Snjl
278167802Sjkim    if (!Pairs)
279167802Sjkim    {
280167802Sjkim        return (AE_OK);
281167802Sjkim    }
282167802Sjkim
283123315Snjl    /*
284117521Snjl     * Entire table scanned, each CR is part of a CR/LF pair --
285117521Snjl     * meaning that the table was treated as a text file somewhere.
286117521Snjl     *
287117521Snjl     * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the
288123315Snjl     * original table are left untouched by the text conversion process --
289117521Snjl     * meaning that we cannot simply replace CR/LF pairs with LFs.
290117521Snjl     */
291117521Snjl    AcpiOsPrintf ("Table has been corrupted by text mode conversion\n");
292209746Sjkim    AcpiOsPrintf ("All LFs (%u) were changed to CR/LF pairs\n", Pairs);
293117521Snjl    AcpiOsPrintf ("Table cannot be repaired!\n");
294117521Snjl    return (AE_BAD_VALUE);
295117521Snjl}
296117521Snjl
297117521Snjl
298117521Snjl/*******************************************************************************
299117521Snjl *
300114237Snjl * FUNCTION:    AcpiDbReadTable
30167754Smsmith *
30267754Smsmith * PARAMETERS:  fp              - File that contains table
303114237Snjl *              Table           - Return value, buffer with table
304114237Snjl *              TableLength     - Return value, length of table
30567754Smsmith *
30667754Smsmith * RETURN:      Status
30767754Smsmith *
30867754Smsmith * DESCRIPTION: Load the DSDT from the file pointer
30967754Smsmith *
31067754Smsmith ******************************************************************************/
31167754Smsmith
31299679Siwasakistatic ACPI_STATUS
313114237SnjlAcpiDbReadTable (
31467754Smsmith    FILE                    *fp,
315114237Snjl    ACPI_TABLE_HEADER       **Table,
31667754Smsmith    UINT32                  *TableLength)
31767754Smsmith{
31867754Smsmith    ACPI_TABLE_HEADER       TableHeader;
31967754Smsmith    UINT32                  Actual;
32069450Smsmith    ACPI_STATUS             Status;
321117521Snjl    UINT32                  FileSize;
322167802Sjkim    BOOLEAN                 StandardHeader = TRUE;
32367754Smsmith
32467754Smsmith
325167802Sjkim    /* Get the file size */
326167802Sjkim
327117521Snjl    fseek (fp, 0, SEEK_END);
328151937Sjkim    FileSize = (UINT32) ftell (fp);
329117521Snjl    fseek (fp, 0, SEEK_SET);
330117521Snjl
331167802Sjkim    if (FileSize < 4)
33267754Smsmith    {
333151937Sjkim        return (AE_BAD_HEADER);
33467754Smsmith    }
33567754Smsmith
336167802Sjkim    /* Read the signature */
33769450Smsmith
338167802Sjkim    if (fread (&TableHeader, 1, 4, fp) != 4)
33967754Smsmith    {
340167802Sjkim        AcpiOsPrintf ("Could not read the table signature\n");
341167802Sjkim        return (AE_BAD_HEADER);
34267754Smsmith    }
34367754Smsmith
344167802Sjkim    fseek (fp, 0, SEEK_SET);
345151937Sjkim
346167802Sjkim    /* The RSDT and FACS tables do not have standard ACPI headers */
347167802Sjkim
348167802Sjkim    if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD ") ||
349167802Sjkim        ACPI_COMPARE_NAME (TableHeader.Signature, "FACS"))
350151937Sjkim    {
351167802Sjkim        *TableLength = FileSize;
352167802Sjkim        StandardHeader = FALSE;
353151937Sjkim    }
354167802Sjkim    else
355167802Sjkim    {
356193267Sjkim        /* Read the table header */
357151937Sjkim
358167802Sjkim        if (fread (&TableHeader, 1, sizeof (TableHeader), fp) !=
359167802Sjkim                sizeof (ACPI_TABLE_HEADER))
360167802Sjkim        {
361167802Sjkim            AcpiOsPrintf ("Could not read the table header\n");
362167802Sjkim            return (AE_BAD_HEADER);
363167802Sjkim        }
36469450Smsmith
365167802Sjkim#if 0
366167802Sjkim        /* Validate the table header/length */
367167802Sjkim
368167802Sjkim        Status = AcpiTbValidateTableHeader (&TableHeader);
369167802Sjkim        if (ACPI_FAILURE (Status))
370167802Sjkim        {
371167802Sjkim            AcpiOsPrintf ("Table header is invalid!\n");
372167802Sjkim            return (Status);
373167802Sjkim        }
374167802Sjkim#endif
375167802Sjkim
376167802Sjkim        /* File size must be at least as long as the Header-specified length */
377167802Sjkim
378167802Sjkim        if (TableHeader.Length > FileSize)
379167802Sjkim        {
380167802Sjkim            AcpiOsPrintf (
381167802Sjkim                "TableHeader length [0x%X] greater than the input file size [0x%X]\n",
382167802Sjkim                TableHeader.Length, FileSize);
383167802Sjkim            return (AE_BAD_HEADER);
384167802Sjkim        }
385167802Sjkim
386167802Sjkim#ifdef ACPI_OBSOLETE_CODE
387167802Sjkim        /* We only support a limited number of table types */
388167802Sjkim
389167802Sjkim        if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) &&
390167802Sjkim            ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) &&
391167802Sjkim            ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4))
392167802Sjkim        {
393167802Sjkim            AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n",
394167802Sjkim                (char *) TableHeader.Signature);
395167802Sjkim            ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
396167802Sjkim            return (AE_ERROR);
397167802Sjkim        }
398167802Sjkim#endif
399167802Sjkim
400167802Sjkim        *TableLength = TableHeader.Length;
40169450Smsmith    }
40269450Smsmith
40367754Smsmith    /* Allocate a buffer for the table */
40467754Smsmith
405167802Sjkim    *Table = AcpiOsAllocate ((size_t) FileSize);
406114237Snjl    if (!*Table)
40767754Smsmith    {
408151937Sjkim        AcpiOsPrintf (
409151937Sjkim            "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
410167802Sjkim            TableHeader.Signature, *TableLength);
41167754Smsmith        return (AE_NO_MEMORY);
41267754Smsmith    }
41367754Smsmith
41467754Smsmith    /* Get the rest of the table */
41567754Smsmith
416117521Snjl    fseek (fp, 0, SEEK_SET);
417117521Snjl    Actual = fread (*Table, 1, (size_t) FileSize, fp);
418117521Snjl    if (Actual == FileSize)
41967754Smsmith    {
420167802Sjkim        if (StandardHeader)
421167802Sjkim        {
422167802Sjkim            /* Now validate the checksum */
423107325Siwasaki
424202771Sjkim            Status = AcpiTbVerifyChecksum ((void *) *Table,
425167802Sjkim                        ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length);
426117521Snjl
427167802Sjkim            if (Status == AE_BAD_CHECKSUM)
428167802Sjkim            {
429167802Sjkim                Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table,
430167802Sjkim                            FileSize, (*Table)->Length);
431167802Sjkim                return (Status);
432167802Sjkim            }
433117521Snjl        }
43467754Smsmith        return (AE_OK);
43567754Smsmith    }
43667754Smsmith
43767754Smsmith    if (Actual > 0)
43867754Smsmith    {
439117521Snjl        AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n",
440117521Snjl            FileSize, Actual);
44184491Smsmith        return (AE_OK);
44267754Smsmith    }
44367754Smsmith
44467754Smsmith    AcpiOsPrintf ("Error - could not read the table file\n");
445114237Snjl    AcpiOsFree (*Table);
446114237Snjl    *Table = NULL;
44767754Smsmith    *TableLength = 0;
44867754Smsmith
44967754Smsmith    return (AE_ERROR);
45067754Smsmith}
45167754Smsmith
45267754Smsmith
45367754Smsmith/*******************************************************************************
45467754Smsmith *
45567754Smsmith * FUNCTION:    AeLocalLoadTable
45667754Smsmith *
457114237Snjl * PARAMETERS:  Table           - pointer to a buffer containing the entire
45867754Smsmith *                                table to be loaded
45967754Smsmith *
46067754Smsmith * RETURN:      Status
46167754Smsmith *
46267754Smsmith * DESCRIPTION: This function is called to load a table from the caller's
463193267Sjkim *              buffer. The buffer must contain an entire ACPI Table including
464193267Sjkim *              a valid header. The header fields will be verified, and if it
46567754Smsmith *              is determined that the table is invalid, the call will fail.
46667754Smsmith *
46767754Smsmith ******************************************************************************/
46867754Smsmith
469151937Sjkimstatic ACPI_STATUS
47067754SmsmithAeLocalLoadTable (
471114237Snjl    ACPI_TABLE_HEADER       *Table)
47267754Smsmith{
473167802Sjkim    ACPI_STATUS             Status = AE_OK;
474167802Sjkim/*    ACPI_TABLE_DESC         TableInfo; */
47567754Smsmith
47667754Smsmith
477167802Sjkim    ACPI_FUNCTION_TRACE (AeLocalLoadTable);
478167802Sjkim#if 0
47967754Smsmith
480114237Snjl
481114237Snjl    if (!Table)
48267754Smsmith    {
48367754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
48467754Smsmith    }
48567754Smsmith
486114237Snjl    TableInfo.Pointer = Table;
487114237Snjl    Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL);
488100966Siwasaki    if (ACPI_FAILURE (Status))
489100966Siwasaki    {
490100966Siwasaki        return_ACPI_STATUS (Status);
491100966Siwasaki    }
492100966Siwasaki
49367754Smsmith    /* Install the new table into the local data structures */
49467754Smsmith
49599679Siwasaki    Status = AcpiTbInstallTable (&TableInfo);
49667754Smsmith    if (ACPI_FAILURE (Status))
49767754Smsmith    {
498151937Sjkim        if (Status == AE_ALREADY_EXISTS)
499151937Sjkim        {
500151937Sjkim            /* Table already exists, no error */
501151937Sjkim
502151937Sjkim            Status = AE_OK;
503151937Sjkim        }
504151937Sjkim
50567754Smsmith        /* Free table allocated by AcpiTbGetTable */
50667754Smsmith
50767754Smsmith        AcpiTbDeleteSingleTable (&TableInfo);
50867754Smsmith        return_ACPI_STATUS (Status);
50967754Smsmith    }
51067754Smsmith
511114237Snjl#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
51267754Smsmith
51367754Smsmith    Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
51467754Smsmith    if (ACPI_FAILURE (Status))
51567754Smsmith    {
51667754Smsmith        /* Uninstall table and free the buffer */
51767754Smsmith
518167802Sjkim        AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT);
51967754Smsmith        return_ACPI_STATUS (Status);
52067754Smsmith    }
52167754Smsmith#endif
522167802Sjkim#endif
52367754Smsmith
52467754Smsmith    return_ACPI_STATUS (Status);
52567754Smsmith}
52667754Smsmith
52767754Smsmith
528107325Siwasaki/*******************************************************************************
529107325Siwasaki *
530114237Snjl * FUNCTION:    AcpiDbReadTableFromFile
531107325Siwasaki *
532114237Snjl * PARAMETERS:  Filename         - File where table is located
533114237Snjl *              Table            - Where a pointer to the table is returned
534107325Siwasaki *
535107325Siwasaki * RETURN:      Status
536107325Siwasaki *
537107325Siwasaki * DESCRIPTION: Get an ACPI table from a file
538107325Siwasaki *
539107325Siwasaki ******************************************************************************/
540107325Siwasaki
54167754SmsmithACPI_STATUS
542114237SnjlAcpiDbReadTableFromFile (
543114237Snjl    char                    *Filename,
544114237Snjl    ACPI_TABLE_HEADER       **Table)
54567754Smsmith{
54667754Smsmith    FILE                    *fp;
54799146Siwasaki    UINT32                  TableLength;
54867754Smsmith    ACPI_STATUS             Status;
54967754Smsmith
550107325Siwasaki
55167754Smsmith    /* Open the file */
55267754Smsmith
55367754Smsmith    fp = fopen (Filename, "rb");
55467754Smsmith    if (!fp)
55567754Smsmith    {
556114237Snjl        AcpiOsPrintf ("Could not open input file %s\n", Filename);
55767754Smsmith        return (AE_ERROR);
55867754Smsmith    }
55967754Smsmith
56067754Smsmith    /* Get the entire file */
56167754Smsmith
562100966Siwasaki    fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
563114237Snjl    Status = AcpiDbReadTable (fp, Table, &TableLength);
56467754Smsmith    fclose(fp);
56567754Smsmith
56667754Smsmith    if (ACPI_FAILURE (Status))
56767754Smsmith    {
568151937Sjkim        AcpiOsPrintf ("Could not get table from the file\n");
56967754Smsmith        return (Status);
57067754Smsmith    }
57167754Smsmith
57299146Siwasaki    return (AE_OK);
57399146Siwasaki }
57499146Siwasaki#endif
57567754Smsmith
576107325Siwasaki
57799146Siwasaki/*******************************************************************************
57899146Siwasaki *
579114237Snjl * FUNCTION:    AcpiDbGetTableFromFile
58099146Siwasaki *
581151937Sjkim * PARAMETERS:  Filename        - File where table is located
582151937Sjkim *              ReturnTable     - Where a pointer to the table is returned
58399146Siwasaki *
58499146Siwasaki * RETURN:      Status
58599146Siwasaki *
58699146Siwasaki * DESCRIPTION: Load an ACPI table from a file
58799146Siwasaki *
58899146Siwasaki ******************************************************************************/
58999146Siwasaki
59099146SiwasakiACPI_STATUS
591114237SnjlAcpiDbGetTableFromFile (
592114237Snjl    char                    *Filename,
593114237Snjl    ACPI_TABLE_HEADER       **ReturnTable)
59499146Siwasaki{
59599146Siwasaki#ifdef ACPI_APPLICATION
59699146Siwasaki    ACPI_STATUS             Status;
597114237Snjl    ACPI_TABLE_HEADER       *Table;
598167802Sjkim    BOOLEAN                 IsAmlTable = TRUE;
59999146Siwasaki
60099146Siwasaki
601114237Snjl    Status = AcpiDbReadTableFromFile (Filename, &Table);
60299146Siwasaki    if (ACPI_FAILURE (Status))
60399146Siwasaki    {
60499146Siwasaki        return (Status);
60599146Siwasaki    }
60699146Siwasaki
607167802Sjkim#ifdef ACPI_DATA_TABLE_DISASSEMBLY
608167802Sjkim    IsAmlTable = AcpiUtIsAmlTable (Table);
609167802Sjkim#endif
61099146Siwasaki
611167802Sjkim    if (IsAmlTable)
61267754Smsmith    {
613167802Sjkim        /* Attempt to recognize and install the table */
614167802Sjkim
615167802Sjkim        Status = AeLocalLoadTable (Table);
616167802Sjkim        if (ACPI_FAILURE (Status))
61767754Smsmith        {
618167802Sjkim            if (Status == AE_ALREADY_EXISTS)
619167802Sjkim            {
620167802Sjkim                AcpiOsPrintf ("Table %4.4s is already installed\n",
621167802Sjkim                    Table->Signature);
622167802Sjkim            }
623167802Sjkim            else
624167802Sjkim            {
625167802Sjkim                AcpiOsPrintf ("Could not install table, %s\n",
626167802Sjkim                    AcpiFormatException (Status));
627167802Sjkim            }
628167802Sjkim
629167802Sjkim            return (Status);
63067754Smsmith        }
63180062Smsmith
632167802Sjkim        fprintf (stderr,
633167802Sjkim            "Acpi table [%4.4s] successfully installed and loaded\n",
634167802Sjkim            Table->Signature);
63567754Smsmith    }
63667754Smsmith
63767754Smsmith    AcpiGbl_AcpiHardwarePresent = FALSE;
638114237Snjl    if (ReturnTable)
639114237Snjl    {
640114237Snjl        *ReturnTable = Table;
641114237Snjl    }
64267754Smsmith
643114237Snjl
64467754Smsmith#endif  /* ACPI_APPLICATION */
64567754Smsmith    return (AE_OK);
64667754Smsmith}
64767754Smsmith
648102550Siwasaki#endif  /* ACPI_DEBUGGER */
64967754Smsmith
650