tbxface.c revision 84491
117658Sjulian/******************************************************************************
217658Sjulian *
317658Sjulian * Module Name: tbxface - Public interfaces to the ACPI subsystem
417658Sjulian *                         ACPI table oriented interfaces
517658Sjulian *              $Revision: 45 $
617658Sjulian *
717658Sjulian *****************************************************************************/
817658Sjulian
917658Sjulian/******************************************************************************
1017658Sjulian *
1117658Sjulian * 1. Copyright Notice
1217658Sjulian *
1317658Sjulian * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
1417658Sjulian * All rights reserved.
1517658Sjulian *
1617658Sjulian * 2. License
1717658Sjulian *
1817658Sjulian * 2.1. This is your license from Intel Corp. under its intellectual property
1917658Sjulian * rights.  You may have additional license terms from the party that provided
2017658Sjulian * you this software, covering your right to use that party's intellectual
2117658Sjulian * property rights.
2217658Sjulian *
2317658Sjulian * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2417658Sjulian * copy of the source code appearing in this file ("Covered Code") an
2517658Sjulian * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2617658Sjulian * base code distributed originally by Intel ("Original Intel Code") to copy,
2717658Sjulian * make derivatives, distribute, use and display any portion of the Covered
2817658Sjulian * Code in any form, with the right to sublicense such rights; and
2917658Sjulian *
3017658Sjulian * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3117658Sjulian * license (with the right to sublicense), under only those claims of Intel
3217658Sjulian * patents that are infringed by the Original Intel Code, to make, use, sell,
3317658Sjulian * offer to sell, and import the Covered Code and derivative works thereof
3417658Sjulian * solely to the minimum extent necessary to exercise the above copyright
3517658Sjulian * license, and in no event shall the patent license extend to any additions
3617658Sjulian * to or modifications of the Original Intel Code.  No other license or right
37116182Sobrien * is granted directly or by implication, estoppel or otherwise;
38116182Sobrien *
39116182Sobrien * The above copyright and patent license is granted only if the following
40131927Smarcel * conditions are met:
4133445Seivind *
42106024Srwatson * 3. Conditions
4328976Sbde *
4428976Sbde * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4517658Sjulian * Redistribution of source code of any substantial portion of the Covered
4617658Sjulian * Code or modification with rights to further distribute source must include
4717658Sjulian * the above Copyright Notice, the above License, this list of Conditions,
4860041Sphk * and the following Disclaimer and Export Compliance provision.  In addition,
4931275Sbde * Licensee must cause all Covered Code to which Licensee contributes to
5078767Sjhb * contain a file documenting the changes Licensee made to create that Covered
5178767Sjhb * Code and the date of any change.  Licensee must include in that file the
5278767Sjhb * documentation of any changes made by any predecessor Licensee.  Licensee
53131927Smarcel * must include a prominent statement that the modification is derived,
5417658Sjulian * directly or indirectly, from Original Intel Code.
5555539Sluoqi *
56106024Srwatson * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5789601Ssobomax * Redistribution of source code of any substantial portion of the Covered
5821776Sbde * Code or modification without rights to further distribute source must
5978767Sjhb * include the following Disclaimer and Export Compliance provision in the
6078767Sjhb * documentation and/or other materials provided with distribution.  In
6178767Sjhb * addition, Licensee may not authorize further sublicense of source of any
6278767Sjhb * portion of the Covered Code, and must include terms to the effect that the
6317658Sjulian * license from Licensee to its licensee is limited to the intellectual
6417658Sjulian * property embodied in the software Licensee provides to its licensee, and
6578767Sjhb * not to intellectual property embodied in modifications its licensee may
6617658Sjulian * make.
67118990Smarcel *
6894169Sphk * 3.3. Redistribution of Executable. Redistribution in executable form of any
6991778Sjake * substantial portion of the Covered Code or modification must reproduce the
7017658Sjulian * above Copyright Notice, and the following Disclaimer and Export Compliance
7117658Sjulian * provision in the documentation and/or other materials provided with the
7217658Sjulian * distribution.
7317658Sjulian *
7417658Sjulian * 3.4. Intel retains all right, title, and interest in and to the Original
7517658Sjulian * Intel Code.
7617658Sjulian *
7717658Sjulian * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7817658Sjulian * Intel shall be used in advertising or otherwise to promote the sale, use or
7917658Sjulian * other dealings in products derived from or relating to the Covered Code
8017658Sjulian * without prior written authorization from Intel.
8117658Sjulian *
8217658Sjulian * 4. Disclaimer and Export Compliance
83131927Smarcel *
84131927Smarcel * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8542135Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8617658Sjulian * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8742135Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8817658Sjulian * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8917658Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
9046381Sbillf * PARTICULAR PURPOSE.
91103647Sjhb *
92131927Smarcel * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93103647Sjhb * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94103647Sjhb * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95103647Sjhb * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9617658Sjulian * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97103647Sjhb * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98103647Sjhb * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99131927Smarcel * LIMITED REMEDY.
10017658Sjulian *
10185202Speter * 4.3. Licensee shall not export, either directly or indirectly, any of this
10285202Speter * software or system incorporating such software without first obtaining any
10385202Speter * required license or other approval from the U. S. Department of Commerce or
10485202Speter * any other agency or department of the United States Government.  In the
10543436Smsmith * event Licensee exports any such software from the United States or
10643436Smsmith * re-exports any such software from a foreign destination, Licensee shall
10728000Sjulian * ensure that the distribution and export/re-export of the software is in
10817658Sjulian * compliance with all laws, regulations, orders, or other restrictions of the
10927997Sjulian * U.S. Export Administration Regulations. Licensee agrees that neither it nor
11027997Sjulian * any of its subsidiaries will export/re-export any technical data, process,
11127997Sjulian * software, or service, directly or indirectly, to any country for which the
11227997Sjulian * United States government or any agency thereof requires an export license,
11327997Sjulian * other governmental approval, or letter of assurance, without first obtaining
11427997Sjulian * such license, approval or letter.
11527997Sjulian *
11628000Sjulian *****************************************************************************/
11727997Sjulian
11827997Sjulian#define __TBXFACE_C__
11917658Sjulian
12017658Sjulian#include "acpi.h"
12117658Sjulian#include "acnamesp.h"
12217658Sjulian#include "acinterp.h"
12317658Sjulian#include "actables.h"
12493496Sphk
12593496Sphk
12667093Sps#define _COMPONENT          ACPI_TABLES
127131927Smarcel        MODULE_NAME         ("tbxface")
128131927Smarcel
129131927Smarcel
130131927Smarcel/*******************************************************************************
13165395Speter *
13265395Speter * FUNCTION:    AcpiLoadTables
13365395Speter *
13465395Speter * PARAMETERS:  None
13565395Speter *
13617658Sjulian * RETURN:      Status
13750107Smsmith *
138110859Salfred * DESCRIPTION: This function is called to load the ACPI tables from the
13950107Smsmith *              provided RSDT
14050107Smsmith *
141110859Salfred ******************************************************************************/
142110859Salfred
143110859SalfredACPI_STATUS
144110859SalfredAcpiLoadTables (void)
145110859Salfred{
146110859Salfred    ACPI_PHYSICAL_ADDRESS   RsdpPhysicalAddress;
147110859Salfred    ACPI_STATUS             Status;
148110859Salfred    UINT32                  NumberOfTables = 0;
149110859Salfred
15050107Smsmith
15148868Sphk    FUNCTION_TRACE ("AcpiLoadTables");
15250107Smsmith
15350107Smsmith
15417658Sjulian    /* Get the RSDP */
15517658Sjulian
15682749Sdillon    Status = AcpiOsGetRootPointer (ACPI_LOGICAL_ADDRESSING,
15782749Sdillon                    &RsdpPhysicalAddress);
15817658Sjulian    if (ACPI_FAILURE (Status))
15982749Sdillon    {
16017658Sjulian        REPORT_ERROR (("AcpiLoadTables: Could not get RSDP, %s\n",
16183366Sjulian                        AcpiFormatException (Status)));
16217658Sjulian        goto ErrorExit;
16317658Sjulian    }
16417658Sjulian
165106024Srwatson    /* Map and validate the RSDP */
166106024Srwatson
167106024Srwatson    Status = AcpiTbVerifyRsdp (RsdpPhysicalAddress);
168106024Srwatson    if (ACPI_FAILURE (Status))
169106024Srwatson    {
170106024Srwatson        REPORT_ERROR (("AcpiLoadTables: RSDP Failed validation: %s\n",
171106024Srwatson                        AcpiFormatException (Status)));
172106024Srwatson        goto ErrorExit;
17382749Sdillon    }
174106024Srwatson
175106024Srwatson    /* Get the RSDT via the RSDP */
17682749Sdillon
17717658Sjulian    Status = AcpiTbGetTableRsdt (&NumberOfTables);
17817658Sjulian    if (ACPI_FAILURE (Status))
17917658Sjulian    {
18017658Sjulian        REPORT_ERROR (("AcpiLoadTables: Could not load RSDT: %s\n",
18117658Sjulian                        AcpiFormatException (Status)));
18265268Smsmith        goto ErrorExit;
18365268Smsmith    }
18417658Sjulian
18565268Smsmith    /* Now get the rest of the tables */
18617658Sjulian
187110859Salfred    Status = AcpiTbGetAllTables (NumberOfTables, NULL);
18865268Smsmith    if (ACPI_FAILURE (Status))
189110859Salfred    {
19017658Sjulian        REPORT_ERROR (("AcpiLoadTables: Error getting required tables (DSDT/FADT/FACS): %s\n",
19117658Sjulian                        AcpiFormatException (Status)));
19273913Sjhb        goto ErrorExit;
19317658Sjulian    }
19473913Sjhb
19517658Sjulian    ACPI_DEBUG_PRINT ((ACPI_DB_OK, "ACPI Tables successfully loaded\n"));
19617658Sjulian
19717658Sjulian
19817658Sjulian    /* Load the namespace from the tables */
19917658Sjulian
20017658Sjulian    Status = AcpiNsLoadNamespace ();
20117658Sjulian    if (ACPI_FAILURE (Status))
20217658Sjulian    {
20354233Sphk        REPORT_ERROR (("AcpiLoadTables: Could not load namespace: %s\n",
20465395Speter                        AcpiFormatException (Status)));
20554233Sphk        goto ErrorExit;
20654233Sphk    }
20754233Sphk
20854233Sphk    return_ACPI_STATUS (AE_OK);
20954233Sphk
21054233Sphk
21154233SphkErrorExit:
21254233Sphk    REPORT_ERROR (("AcpiLoadTables: Could not load tables: %s\n",
21365764Sjhb                    AcpiFormatException (Status)));
21454233Sphk
21554233Sphk    return_ACPI_STATUS (Status);
21654233Sphk}
21754233Sphk
21865764Sjhb
21954233Sphk/*******************************************************************************
22054233Sphk *
22154233Sphk * FUNCTION:    AcpiLoadTable
22254233Sphk *
22365764Sjhb * PARAMETERS:  TablePtr        - pointer to a buffer containing the entire
22454233Sphk *                                table to be loaded
22554233Sphk *
22654233Sphk * RETURN:      Status
22765764Sjhb *
22854233Sphk * DESCRIPTION: This function is called to load a table from the caller's
22954233Sphk *              buffer.  The buffer must contain an entire ACPI Table including
23094169Sphk *              a valid header.  The header fields will be verified, and if it
23194169Sphk *              is determined that the table is invalid, the call will fail.
23294169Sphk *
233110859Salfred ******************************************************************************/
234132412Sjulian
235132412SjulianACPI_STATUS
236132412SjulianAcpiLoadTable (
237132412Sjulian    ACPI_TABLE_HEADER       *TablePtr)
238132412Sjulian{
239132412Sjulian    ACPI_STATUS             Status;
240132412Sjulian    ACPI_TABLE_DESC         TableInfo;
241132412Sjulian
242132412Sjulian
243132412Sjulian    FUNCTION_TRACE ("AcpiLoadTable");
24494169Sphk
245131927Smarcel
24694169Sphk    if (!TablePtr)
24794169Sphk    {
24894169Sphk        return_ACPI_STATUS (AE_BAD_PARAMETER);
24994169Sphk    }
25017658Sjulian
25117658Sjulian    /* Copy the table to a local buffer */
25217658Sjulian
25317658Sjulian    Status = AcpiTbGetTable (0, TablePtr, &TableInfo);
25417658Sjulian    if (ACPI_FAILURE (Status))
25531275Sbde    {
25665395Speter        return_ACPI_STATUS (Status);
25717658Sjulian    }
258132197Salfred
25917658Sjulian    /* Install the new table into the local data structures */
26065268Smsmith
26165268Smsmith    Status = AcpiTbInstallTable (NULL, &TableInfo);
26265268Smsmith    if (ACPI_FAILURE (Status))
26382119Sjhb    {
264131927Smarcel        /* Free table allocated by AcpiTbGetTable */
26582119Sjhb
26625164Speter        AcpiTbDeleteSingleTable (&TableInfo);
26765395Speter        return_ACPI_STATUS (Status);
26870861Sjake    }
26925164Speter
27027997Sjulian
27127997Sjulian    Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
27227997Sjulian    if (ACPI_FAILURE (Status))
27350107Smsmith    {
27427997Sjulian        /* Uninstall table and free the buffer */
27527997Sjulian
27627997Sjulian        AcpiTbUninstallTable (TableInfo.InstalledDesc);
27727997Sjulian        return_ACPI_STATUS (Status);
27817658Sjulian    }
27917658Sjulian
28065707Sjasone
281131481Sjhb    return_ACPI_STATUS (Status);
28265707Sjasone}
283131481Sjhb
28417658Sjulian
28517658Sjulian/*******************************************************************************
28617658Sjulian *
28790361Sjulian * FUNCTION:    AcpiUnloadTable
28817658Sjulian *
28934266Sjulian * PARAMETERS:  TableType     - Type of table to be unloaded
29034266Sjulian *
29134266Sjulian * RETURN:      Status
29234266Sjulian *
29334266Sjulian * DESCRIPTION: This routine is used to force the unload of a table
29465707Sjasone *
29517658Sjulian ******************************************************************************/
29617658Sjulian
29748225SmckusickACPI_STATUS
29848225SmckusickAcpiUnloadTable (
29917658Sjulian    ACPI_TABLE_TYPE         TableType)
30034266Sjulian{
30134266Sjulian    ACPI_TABLE_DESC         *ListHead;
30234266Sjulian
30334266Sjulian
30417658Sjulian    FUNCTION_TRACE ("AcpiUnloadTable");
30517658Sjulian
30617658Sjulian
30717658Sjulian    /* Parameter validation */
308132177Salfred
309132177Salfred    if (TableType > ACPI_TABLE_MAX)
310132177Salfred    {
311132177Salfred        return_ACPI_STATUS (AE_BAD_PARAMETER);
31217658Sjulian    }
31365707Sjasone
31465707Sjasone
31565707Sjasone    /* Find all tables of the requested type */
31690361Sjulian
317131481Sjhb    ListHead = &AcpiGbl_AcpiTables[TableType];
318131481Sjhb    do
319131481Sjhb    {
320131481Sjhb        /*
321131481Sjhb         * Delete all namespace entries owned by this table.  Note that these
322131481Sjhb         * entries can appear anywhere in the namespace by virtue of the AML
323131481Sjhb         * "Scope" operator.  Thus, we need to track ownership by an ID, not
32434266Sjulian         * simply a position within the hierarchy
325131481Sjhb         */
326131481Sjhb        AcpiNsDeleteNamespaceByOwner (ListHead->TableId);
327131481Sjhb
328131481Sjhb        /* Delete (or unmap) the actual table */
329131481Sjhb
330131481Sjhb        AcpiTbDeleteAcpiTable (TableType);
331131481Sjhb
332131481Sjhb    } while (ListHead != &AcpiGbl_AcpiTables[TableType]);
333131481Sjhb
334131481Sjhb    return_ACPI_STATUS (AE_OK);
335131481Sjhb}
336131481Sjhb
337131481Sjhb
338131481Sjhb/*******************************************************************************
339131481Sjhb *
34017658Sjulian * FUNCTION:    AcpiGetTableHeader
341132171Snjl *
34241137Smsmith * PARAMETERS:  TableType       - one of the defined table types
34341137Smsmith *              Instance        - the non zero instance of the table, allows
34441137Smsmith *                                support for multiple tables of the same type
34541137Smsmith *                                see AcpiGbl_AcpiTableFlag
34641137Smsmith *              OutTableHeader  - pointer to the ACPI_TABLE_HEADER if successful
34741137Smsmith *
34848225Smckusick * DESCRIPTION: This function is called to get an ACPI table header.  The caller
34948225Smckusick *              supplies an pointer to a data area sufficient to contain an ACPI
350130640Sphk *              ACPI_TABLE_HEADER structure.
35153452Sphk *
35248225Smckusick *              The header contains a length field that can be used to determine
35353023Sphk *              the size of the buffer needed to contain the entire table.  This
35453023Sphk *              function is not valid for the RSD PTR table since it does not
35553023Sphk *              have a standard header and is fixed length.
35653023Sphk *
35753023Sphk ******************************************************************************/
358110585Sjeff
35953023SphkACPI_STATUS
36053023SphkAcpiGetTableHeader (
36153023Sphk    ACPI_TABLE_TYPE         TableType,
36253023Sphk    UINT32                  Instance,
36346568Speter    ACPI_TABLE_HEADER       *OutTableHeader)
36441137Smsmith{
36517658Sjulian    ACPI_TABLE_HEADER       *TblPtr;
36617658Sjulian    ACPI_STATUS             Status;
36717658Sjulian
36817658Sjulian
36917658Sjulian    FUNCTION_TRACE ("AcpiGetTableHeader");
37053023Sphk
37117658Sjulian
37217658Sjulian    if ((Instance == 0)                 ||
37317658Sjulian        (TableType == ACPI_TABLE_RSDP)  ||
37417658Sjulian        (!OutTableHeader))
37517658Sjulian    {
37617658Sjulian        return_ACPI_STATUS (AE_BAD_PARAMETER);
37717658Sjulian    }
37817658Sjulian
37917658Sjulian    /* Check the table type and instance */
38039237Sgibbs
38117658Sjulian    if ((TableType > ACPI_TABLE_MAX)    ||
38227997Sjulian        (IS_SINGLE_TABLE (AcpiGbl_AcpiTableData[TableType].Flags) &&
38354233Sphk         Instance > 1))
38454233Sphk    {
38527997Sjulian        return_ACPI_STATUS (AE_BAD_PARAMETER);
38627997Sjulian    }
38727997Sjulian
38827997Sjulian
38950107Smsmith    /* Get a pointer to the entire table */
39039237Sgibbs
391132412Sjulian    Status = AcpiTbGetTablePtr (TableType, Instance, &TblPtr);
39294169Sphk    if (ACPI_FAILURE (Status))
39339237Sgibbs    {
39439237Sgibbs        return_ACPI_STATUS (Status);
39550107Smsmith    }
39639237Sgibbs
39750107Smsmith    /*
39850107Smsmith     * The function will return a NULL pointer if the table is not loaded
39950107Smsmith     */
40050107Smsmith    if (TblPtr == NULL)
40150107Smsmith    {
40250107Smsmith        return_ACPI_STATUS (AE_NOT_EXIST);
40350107Smsmith    }
40450107Smsmith
40550107Smsmith    /*
40650107Smsmith     * Copy the header to the caller's buffer
407110859Salfred     */
40817658Sjulian    MEMCPY ((void *) OutTableHeader, (void *) TblPtr,
40917658Sjulian                sizeof (ACPI_TABLE_HEADER));
41017658Sjulian
41117658Sjulian    return_ACPI_STATUS (Status);
41219274Sjulian}
41319274Sjulian
41419274Sjulian
41519274Sjulian/*******************************************************************************
41619274Sjulian *
41739237Sgibbs * FUNCTION:    AcpiGetTable
41819274Sjulian *
41919274Sjulian * PARAMETERS:  TableType       - one of the defined table types
42050107Smsmith *              Instance        - the non zero instance of the table, allows
42150107Smsmith *                                support for multiple tables of the same type
42217658Sjulian *                                see AcpiGbl_AcpiTableFlag
42350107Smsmith *              RetBuffer       - pointer to a structure containing a buffer to
42450107Smsmith *                                receive the table
42550107Smsmith *
42650107Smsmith * RETURN:      Status
42750107Smsmith *
42850107Smsmith * DESCRIPTION: This function is called to get an ACPI table.  The caller
42950107Smsmith *              supplies an OutBuffer large enough to contain the entire ACPI
43050107Smsmith *              table.  The caller should call the AcpiGetTableHeader function
43150107Smsmith *              first to determine the buffer size needed.  Upon completion
43250107Smsmith *              the OutBuffer->Length field will indicate the number of bytes
43339237Sgibbs *              copied into the OutBuffer->BufPtr buffer.  This table will be
43439237Sgibbs *              a complete table including the header.
43539237Sgibbs *
43639237Sgibbs ******************************************************************************/
43739237Sgibbs
43839237SgibbsACPI_STATUS
43939237SgibbsAcpiGetTable (
44039237Sgibbs    ACPI_TABLE_TYPE         TableType,
44139237Sgibbs    UINT32                  Instance,
44239237Sgibbs    ACPI_BUFFER             *RetBuffer)
44339237Sgibbs{
44417658Sjulian    ACPI_TABLE_HEADER       *TblPtr;
44539237Sgibbs    ACPI_STATUS             Status;
44650107Smsmith    UINT32                  RetBufLen;
44717658Sjulian
44839237Sgibbs
44950107Smsmith    FUNCTION_TRACE ("AcpiGetTable");
45017658Sjulian
45189522Snik
45289522Snik    /*
45339237Sgibbs     *  If we have a buffer, we must have a length too
45417658Sjulian     */
45550107Smsmith    if ((Instance == 0)                 ||
45650107Smsmith        (!RetBuffer)                    ||
45750107Smsmith        ((!RetBuffer->Pointer) && (RetBuffer->Length)))
45850107Smsmith    {
45950107Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
46050107Smsmith    }
46150107Smsmith
46250107Smsmith    /* Check the table type and instance */
463110859Salfred
46417658Sjulian    if ((TableType > ACPI_TABLE_MAX)    ||
46517658Sjulian        (IS_SINGLE_TABLE (AcpiGbl_AcpiTableData[TableType].Flags) &&
46617677Sjulian         Instance > 1))
46717658Sjulian    {
46850107Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
46917658Sjulian    }
47017658Sjulian
47175570Sjhb
472101155Sjhb    /* Get a pointer to the entire table */
47375570Sjhb
47475570Sjhb    Status = AcpiTbGetTablePtr (TableType, Instance, &TblPtr);
47517658Sjulian    if (ACPI_FAILURE (Status))
47617658Sjulian    {
47717658Sjulian        return_ACPI_STATUS (Status);
47817658Sjulian    }
47982749Sdillon
48082749Sdillon    /*
48117658Sjulian     * AcpiTbGetTablePtr will return a NULL pointer if the
48217658Sjulian     * table is not loaded.
483130164Sphk     */
48417658Sjulian    if (TblPtr == NULL)
485100209Sgallatin    {
486103647Sjhb        return_ACPI_STATUS (AE_NOT_EXIST);
48717658Sjulian    }
48838874Sache
48917658Sjulian    /*
49065557Sjasone     * Got a table ptr, assume it's ok and copy it to the user's buffer
49182115Sjhb     */
49282115Sjhb    if (TableType == ACPI_TABLE_RSDP)
493101155Sjhb    {
494101155Sjhb        /*
49582115Sjhb         *  RSD PTR is the only "table" without a header
49682115Sjhb         */
497101155Sjhb        RetBufLen = sizeof (RSDP_DESCRIPTOR);
498101155Sjhb    }
499101155Sjhb    else
500101155Sjhb    {
501101155Sjhb        RetBufLen = TblPtr->Length;
50265557Sjasone    }
50365557Sjasone
50417658Sjulian    /*
505103647Sjhb     * Verify we have space in the caller's buffer for the table
50617658Sjulian     */
50717658Sjulian    if (RetBuffer->Length < RetBufLen)
508103647Sjhb    {
50917658Sjulian        RetBuffer->Length = RetBufLen;
510103647Sjhb        return_ACPI_STATUS (AE_BUFFER_OVERFLOW);
511103647Sjhb    }
51217658Sjulian
51317658Sjulian    RetBuffer->Length = RetBufLen;
514116398Siedowse
515116398Siedowse    MEMCPY ((void *) RetBuffer->Pointer, (void *) TblPtr, RetBufLen);
51638874Sache
517130164Sphk    return_ACPI_STATUS (AE_OK);
518116398Siedowse}
519116398Siedowse
520116398Siedowse
521130164Sphk