tbxface.c revision 91116
167754Smsmith/******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: tbxface - Public interfaces to the ACPI subsystem
467754Smsmith *                         ACPI table oriented interfaces
591116Smsmith *              $Revision: 51 $
667754Smsmith *
767754Smsmith *****************************************************************************/
867754Smsmith
967754Smsmith/******************************************************************************
1067754Smsmith *
1167754Smsmith * 1. Copyright Notice
1267754Smsmith *
1391116Smsmith * Some or all of this work - Copyright (c) 1999 - 2002, 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#define __TBXFACE_C__
11967754Smsmith
12067754Smsmith#include "acpi.h"
12167754Smsmith#include "acnamesp.h"
12267754Smsmith#include "acinterp.h"
12367754Smsmith#include "actables.h"
12467754Smsmith
12567754Smsmith
12677424Smsmith#define _COMPONENT          ACPI_TABLES
12791116Smsmith        ACPI_MODULE_NAME    ("tbxface")
12867754Smsmith
12967754Smsmith
13067754Smsmith/*******************************************************************************
13167754Smsmith *
13267754Smsmith * FUNCTION:    AcpiLoadTables
13367754Smsmith *
13467754Smsmith * PARAMETERS:  None
13567754Smsmith *
13667754Smsmith * RETURN:      Status
13767754Smsmith *
13867754Smsmith * DESCRIPTION: This function is called to load the ACPI tables from the
13967754Smsmith *              provided RSDT
14067754Smsmith *
14167754Smsmith ******************************************************************************/
14267754Smsmith
14367754SmsmithACPI_STATUS
14480062SmsmithAcpiLoadTables (void)
14567754Smsmith{
14680062Smsmith    ACPI_PHYSICAL_ADDRESS   RsdpPhysicalAddress;
14777424Smsmith    ACPI_STATUS             Status;
14867754Smsmith    UINT32                  NumberOfTables = 0;
14967754Smsmith
15067754Smsmith
15191116Smsmith    ACPI_FUNCTION_TRACE ("AcpiLoadTables");
15267754Smsmith
15367754Smsmith
15480062Smsmith    /* Get the RSDP */
15580062Smsmith
15683174Smsmith    Status = AcpiOsGetRootPointer (ACPI_LOGICAL_ADDRESSING,
15780062Smsmith                    &RsdpPhysicalAddress);
15880062Smsmith    if (ACPI_FAILURE (Status))
15980062Smsmith    {
16091116Smsmith        ACPI_REPORT_ERROR (("AcpiLoadTables: Could not get RSDP, %s\n",
16180062Smsmith                        AcpiFormatException (Status)));
16280062Smsmith        goto ErrorExit;
16380062Smsmith    }
16480062Smsmith
16567754Smsmith    /* Map and validate the RSDP */
16667754Smsmith
16767754Smsmith    Status = AcpiTbVerifyRsdp (RsdpPhysicalAddress);
16867754Smsmith    if (ACPI_FAILURE (Status))
16967754Smsmith    {
17091116Smsmith        ACPI_REPORT_ERROR (("AcpiLoadTables: RSDP Failed validation: %s\n",
17180062Smsmith                        AcpiFormatException (Status)));
17267754Smsmith        goto ErrorExit;
17367754Smsmith    }
17467754Smsmith
17567754Smsmith    /* Get the RSDT via the RSDP */
17667754Smsmith
17767754Smsmith    Status = AcpiTbGetTableRsdt (&NumberOfTables);
17867754Smsmith    if (ACPI_FAILURE (Status))
17967754Smsmith    {
18091116Smsmith        ACPI_REPORT_ERROR (("AcpiLoadTables: Could not load RSDT: %s\n",
18180062Smsmith                        AcpiFormatException (Status)));
18267754Smsmith        goto ErrorExit;
18367754Smsmith    }
18467754Smsmith
18567754Smsmith    /* Now get the rest of the tables */
18667754Smsmith
18767754Smsmith    Status = AcpiTbGetAllTables (NumberOfTables, NULL);
18867754Smsmith    if (ACPI_FAILURE (Status))
18967754Smsmith    {
19091116Smsmith        ACPI_REPORT_ERROR (("AcpiLoadTables: Error getting required tables (DSDT/FADT/FACS): %s\n",
19180062Smsmith                        AcpiFormatException (Status)));
19267754Smsmith        goto ErrorExit;
19367754Smsmith    }
19467754Smsmith
19582367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_OK, "ACPI Tables successfully loaded\n"));
19667754Smsmith
19767754Smsmith
19867754Smsmith    /* Load the namespace from the tables */
19967754Smsmith
20067754Smsmith    Status = AcpiNsLoadNamespace ();
20167754Smsmith    if (ACPI_FAILURE (Status))
20267754Smsmith    {
20391116Smsmith        ACPI_REPORT_ERROR (("AcpiLoadTables: Could not load namespace: %s\n",
20480062Smsmith                        AcpiFormatException (Status)));
20567754Smsmith        goto ErrorExit;
20667754Smsmith    }
20767754Smsmith
20867754Smsmith    return_ACPI_STATUS (AE_OK);
20967754Smsmith
21067754Smsmith
21167754SmsmithErrorExit:
21291116Smsmith    ACPI_REPORT_ERROR (("AcpiLoadTables: Could not load tables: %s\n",
21380062Smsmith                    AcpiFormatException (Status)));
21467754Smsmith
21567754Smsmith    return_ACPI_STATUS (Status);
21667754Smsmith}
21767754Smsmith
21867754Smsmith
21967754Smsmith/*******************************************************************************
22067754Smsmith *
22167754Smsmith * FUNCTION:    AcpiLoadTable
22267754Smsmith *
22367754Smsmith * PARAMETERS:  TablePtr        - pointer to a buffer containing the entire
22467754Smsmith *                                table to be loaded
22567754Smsmith *
22667754Smsmith * RETURN:      Status
22767754Smsmith *
22867754Smsmith * DESCRIPTION: This function is called to load a table from the caller's
22967754Smsmith *              buffer.  The buffer must contain an entire ACPI Table including
23067754Smsmith *              a valid header.  The header fields will be verified, and if it
23167754Smsmith *              is determined that the table is invalid, the call will fail.
23267754Smsmith *
23367754Smsmith ******************************************************************************/
23467754Smsmith
23567754SmsmithACPI_STATUS
23667754SmsmithAcpiLoadTable (
23767754Smsmith    ACPI_TABLE_HEADER       *TablePtr)
23867754Smsmith{
23967754Smsmith    ACPI_STATUS             Status;
24067754Smsmith    ACPI_TABLE_DESC         TableInfo;
24167754Smsmith
24267754Smsmith
24391116Smsmith    ACPI_FUNCTION_TRACE ("AcpiLoadTable");
24467754Smsmith
24577424Smsmith
24667754Smsmith    if (!TablePtr)
24767754Smsmith    {
24867754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
24967754Smsmith    }
25067754Smsmith
25167754Smsmith    /* Copy the table to a local buffer */
25267754Smsmith
25369450Smsmith    Status = AcpiTbGetTable (0, TablePtr, &TableInfo);
25467754Smsmith    if (ACPI_FAILURE (Status))
25567754Smsmith    {
25667754Smsmith        return_ACPI_STATUS (Status);
25767754Smsmith    }
25867754Smsmith
25967754Smsmith    /* Install the new table into the local data structures */
26067754Smsmith
26167754Smsmith    Status = AcpiTbInstallTable (NULL, &TableInfo);
26267754Smsmith    if (ACPI_FAILURE (Status))
26367754Smsmith    {
26467754Smsmith        /* Free table allocated by AcpiTbGetTable */
26567754Smsmith
26667754Smsmith        AcpiTbDeleteSingleTable (&TableInfo);
26767754Smsmith        return_ACPI_STATUS (Status);
26867754Smsmith    }
26967754Smsmith
27091116Smsmith    /* Convert the table to common format if necessary */
27167754Smsmith
27291116Smsmith    switch (TableInfo.Type)
27391116Smsmith    {
27491116Smsmith    case ACPI_TABLE_FADT:
27591116Smsmith
27691116Smsmith        Status = AcpiTbConvertTableFadt ();
27791116Smsmith        break;
27891116Smsmith
27991116Smsmith    case ACPI_TABLE_FACS:
28091116Smsmith
28191116Smsmith        Status = AcpiTbBuildCommonFacs (&TableInfo);
28291116Smsmith        break;
28391116Smsmith
28491116Smsmith    default:
28591116Smsmith        /* Load table into namespace if it contains executable AML */
28691116Smsmith
28791116Smsmith        Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
28891116Smsmith        break;
28991116Smsmith    }
29091116Smsmith
29167754Smsmith    if (ACPI_FAILURE (Status))
29267754Smsmith    {
29367754Smsmith        /* Uninstall table and free the buffer */
29467754Smsmith
29567754Smsmith        AcpiTbUninstallTable (TableInfo.InstalledDesc);
29667754Smsmith    }
29767754Smsmith
29867754Smsmith    return_ACPI_STATUS (Status);
29967754Smsmith}
30067754Smsmith
30167754Smsmith
30267754Smsmith/*******************************************************************************
30367754Smsmith *
30467754Smsmith * FUNCTION:    AcpiUnloadTable
30567754Smsmith *
30667754Smsmith * PARAMETERS:  TableType     - Type of table to be unloaded
30767754Smsmith *
30867754Smsmith * RETURN:      Status
30967754Smsmith *
31067754Smsmith * DESCRIPTION: This routine is used to force the unload of a table
31167754Smsmith *
31267754Smsmith ******************************************************************************/
31367754Smsmith
31467754SmsmithACPI_STATUS
31567754SmsmithAcpiUnloadTable (
31667754Smsmith    ACPI_TABLE_TYPE         TableType)
31767754Smsmith{
31867754Smsmith    ACPI_TABLE_DESC         *ListHead;
31967754Smsmith
32067754Smsmith
32191116Smsmith    ACPI_FUNCTION_TRACE ("AcpiUnloadTable");
32267754Smsmith
32367754Smsmith
32467754Smsmith    /* Parameter validation */
32567754Smsmith
32667754Smsmith    if (TableType > ACPI_TABLE_MAX)
32767754Smsmith    {
32867754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
32967754Smsmith    }
33067754Smsmith
33167754Smsmith
33267754Smsmith    /* Find all tables of the requested type */
33367754Smsmith
33467754Smsmith    ListHead = &AcpiGbl_AcpiTables[TableType];
33567754Smsmith    do
33667754Smsmith    {
33767754Smsmith        /*
33867754Smsmith         * Delete all namespace entries owned by this table.  Note that these
33967754Smsmith         * entries can appear anywhere in the namespace by virtue of the AML
34067754Smsmith         * "Scope" operator.  Thus, we need to track ownership by an ID, not
34167754Smsmith         * simply a position within the hierarchy
34267754Smsmith         */
34367754Smsmith        AcpiNsDeleteNamespaceByOwner (ListHead->TableId);
34467754Smsmith
34567754Smsmith        /* Delete (or unmap) the actual table */
34667754Smsmith
34767754Smsmith        AcpiTbDeleteAcpiTable (TableType);
34867754Smsmith
34967754Smsmith    } while (ListHead != &AcpiGbl_AcpiTables[TableType]);
35067754Smsmith
35167754Smsmith    return_ACPI_STATUS (AE_OK);
35267754Smsmith}
35367754Smsmith
35467754Smsmith
35567754Smsmith/*******************************************************************************
35667754Smsmith *
35767754Smsmith * FUNCTION:    AcpiGetTableHeader
35867754Smsmith *
35967754Smsmith * PARAMETERS:  TableType       - one of the defined table types
36067754Smsmith *              Instance        - the non zero instance of the table, allows
36167754Smsmith *                                support for multiple tables of the same type
36267754Smsmith *                                see AcpiGbl_AcpiTableFlag
36367754Smsmith *              OutTableHeader  - pointer to the ACPI_TABLE_HEADER if successful
36467754Smsmith *
36567754Smsmith * DESCRIPTION: This function is called to get an ACPI table header.  The caller
36667754Smsmith *              supplies an pointer to a data area sufficient to contain an ACPI
36767754Smsmith *              ACPI_TABLE_HEADER structure.
36867754Smsmith *
36967754Smsmith *              The header contains a length field that can be used to determine
37067754Smsmith *              the size of the buffer needed to contain the entire table.  This
37167754Smsmith *              function is not valid for the RSD PTR table since it does not
37267754Smsmith *              have a standard header and is fixed length.
37367754Smsmith *
37467754Smsmith ******************************************************************************/
37567754Smsmith
37667754SmsmithACPI_STATUS
37767754SmsmithAcpiGetTableHeader (
37867754Smsmith    ACPI_TABLE_TYPE         TableType,
37967754Smsmith    UINT32                  Instance,
38067754Smsmith    ACPI_TABLE_HEADER       *OutTableHeader)
38167754Smsmith{
38267754Smsmith    ACPI_TABLE_HEADER       *TblPtr;
38367754Smsmith    ACPI_STATUS             Status;
38467754Smsmith
38567754Smsmith
38691116Smsmith    ACPI_FUNCTION_TRACE ("AcpiGetTableHeader");
38767754Smsmith
38877424Smsmith
38967754Smsmith    if ((Instance == 0)                 ||
39067754Smsmith        (TableType == ACPI_TABLE_RSDP)  ||
39167754Smsmith        (!OutTableHeader))
39267754Smsmith    {
39367754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
39467754Smsmith    }
39567754Smsmith
39667754Smsmith    /* Check the table type and instance */
39767754Smsmith
39867754Smsmith    if ((TableType > ACPI_TABLE_MAX)    ||
39991116Smsmith        (ACPI_IS_SINGLE_TABLE (AcpiGbl_AcpiTableData[TableType].Flags) &&
40067754Smsmith         Instance > 1))
40167754Smsmith    {
40267754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
40367754Smsmith    }
40467754Smsmith
40567754Smsmith
40667754Smsmith    /* Get a pointer to the entire table */
40767754Smsmith
40867754Smsmith    Status = AcpiTbGetTablePtr (TableType, Instance, &TblPtr);
40967754Smsmith    if (ACPI_FAILURE (Status))
41067754Smsmith    {
41167754Smsmith        return_ACPI_STATUS (Status);
41267754Smsmith    }
41367754Smsmith
41467754Smsmith    /*
41567754Smsmith     * The function will return a NULL pointer if the table is not loaded
41667754Smsmith     */
41767754Smsmith    if (TblPtr == NULL)
41867754Smsmith    {
41967754Smsmith        return_ACPI_STATUS (AE_NOT_EXIST);
42067754Smsmith    }
42167754Smsmith
42267754Smsmith    /*
42367754Smsmith     * Copy the header to the caller's buffer
42467754Smsmith     */
42591116Smsmith    ACPI_MEMCPY ((void *) OutTableHeader, (void *) TblPtr,
42667754Smsmith                sizeof (ACPI_TABLE_HEADER));
42767754Smsmith
42867754Smsmith    return_ACPI_STATUS (Status);
42967754Smsmith}
43067754Smsmith
43167754Smsmith
43267754Smsmith/*******************************************************************************
43367754Smsmith *
43467754Smsmith * FUNCTION:    AcpiGetTable
43567754Smsmith *
43667754Smsmith * PARAMETERS:  TableType       - one of the defined table types
43767754Smsmith *              Instance        - the non zero instance of the table, allows
43867754Smsmith *                                support for multiple tables of the same type
43967754Smsmith *                                see AcpiGbl_AcpiTableFlag
44067754Smsmith *              RetBuffer       - pointer to a structure containing a buffer to
44167754Smsmith *                                receive the table
44267754Smsmith *
44367754Smsmith * RETURN:      Status
44467754Smsmith *
44567754Smsmith * DESCRIPTION: This function is called to get an ACPI table.  The caller
44667754Smsmith *              supplies an OutBuffer large enough to contain the entire ACPI
44767754Smsmith *              table.  The caller should call the AcpiGetTableHeader function
44867754Smsmith *              first to determine the buffer size needed.  Upon completion
44967754Smsmith *              the OutBuffer->Length field will indicate the number of bytes
45067754Smsmith *              copied into the OutBuffer->BufPtr buffer.  This table will be
45167754Smsmith *              a complete table including the header.
45267754Smsmith *
45367754Smsmith ******************************************************************************/
45467754Smsmith
45567754SmsmithACPI_STATUS
45667754SmsmithAcpiGetTable (
45767754Smsmith    ACPI_TABLE_TYPE         TableType,
45867754Smsmith    UINT32                  Instance,
45967754Smsmith    ACPI_BUFFER             *RetBuffer)
46067754Smsmith{
46167754Smsmith    ACPI_TABLE_HEADER       *TblPtr;
46267754Smsmith    ACPI_STATUS             Status;
46391116Smsmith    UINT32                  TableLength;
46467754Smsmith
46567754Smsmith
46691116Smsmith    ACPI_FUNCTION_TRACE ("AcpiGetTable");
46767754Smsmith
46877424Smsmith
46991116Smsmith    /* Parameter validation */
47091116Smsmith
47191116Smsmith    if (Instance == 0)
47267754Smsmith    {
47367754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
47467754Smsmith    }
47567754Smsmith
47691116Smsmith    Status = AcpiUtValidateBuffer (RetBuffer);
47791116Smsmith    if (ACPI_FAILURE (Status))
47891116Smsmith    {
47991116Smsmith        return_ACPI_STATUS (Status);
48091116Smsmith    }
48191116Smsmith
48267754Smsmith    /* Check the table type and instance */
48367754Smsmith
48467754Smsmith    if ((TableType > ACPI_TABLE_MAX)    ||
48591116Smsmith        (ACPI_IS_SINGLE_TABLE (AcpiGbl_AcpiTableData[TableType].Flags) &&
48667754Smsmith         Instance > 1))
48767754Smsmith    {
48867754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
48967754Smsmith    }
49067754Smsmith
49167754Smsmith
49267754Smsmith    /* Get a pointer to the entire table */
49367754Smsmith
49467754Smsmith    Status = AcpiTbGetTablePtr (TableType, Instance, &TblPtr);
49567754Smsmith    if (ACPI_FAILURE (Status))
49667754Smsmith    {
49767754Smsmith        return_ACPI_STATUS (Status);
49867754Smsmith    }
49967754Smsmith
50067754Smsmith    /*
50167754Smsmith     * AcpiTbGetTablePtr will return a NULL pointer if the
50278986Smsmith     * table is not loaded.
50367754Smsmith     */
50467754Smsmith    if (TblPtr == NULL)
50567754Smsmith    {
50667754Smsmith        return_ACPI_STATUS (AE_NOT_EXIST);
50767754Smsmith    }
50867754Smsmith
50991116Smsmith    /* Get the table length */
51091116Smsmith
51167754Smsmith    if (TableType == ACPI_TABLE_RSDP)
51267754Smsmith    {
51367754Smsmith        /*
51467754Smsmith         *  RSD PTR is the only "table" without a header
51567754Smsmith         */
51691116Smsmith        TableLength = sizeof (RSDP_DESCRIPTOR);
51767754Smsmith    }
51867754Smsmith    else
51967754Smsmith    {
52091116Smsmith        TableLength = TblPtr->Length;
52167754Smsmith    }
52267754Smsmith
52391116Smsmith    /* Validate/Allocate/Clear caller buffer */
52491116Smsmith
52591116Smsmith    Status = AcpiUtInitializeBuffer (RetBuffer, TableLength);
52691116Smsmith    if (ACPI_FAILURE (Status))
52767754Smsmith    {
52891116Smsmith        return_ACPI_STATUS (Status);
52967754Smsmith    }
53067754Smsmith
53191116Smsmith    /* Copy the table to the buffer */
53267754Smsmith
53391116Smsmith    ACPI_MEMCPY ((void *) RetBuffer->Pointer, (void *) TblPtr, TableLength);
53467754Smsmith    return_ACPI_STATUS (AE_OK);
53567754Smsmith}
53667754Smsmith
53778986Smsmith
538