rsutils.c revision 99679
160786Sps/*******************************************************************************
260786Sps *
360786Sps * Module Name: rsutils - Utilities for the resource manager
460786Sps *              $Revision: 33 $
560786Sps *
660786Sps ******************************************************************************/
760786Sps
860786Sps/******************************************************************************
960786Sps *
1060786Sps * 1. Copyright Notice
1160786Sps *
1260786Sps * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
1360786Sps * All rights reserved.
1460786Sps *
1560786Sps * 2. License
1660786Sps *
1760786Sps * 2.1. This is your license from Intel Corp. under its intellectual property
1860786Sps * rights.  You may have additional license terms from the party that provided
1960786Sps * you this software, covering your right to use that party's intellectual
2060786Sps * property rights.
2160786Sps *
2260786Sps * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2360786Sps * copy of the source code appearing in this file ("Covered Code") an
2460786Sps * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2560786Sps * base code distributed originally by Intel ("Original Intel Code") to copy,
2660786Sps * make derivatives, distribute, use and display any portion of the Covered
2760786Sps * Code in any form, with the right to sublicense such rights; and
2860786Sps *
2960786Sps * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3060786Sps * license (with the right to sublicense), under only those claims of Intel
3160786Sps * patents that are infringed by the Original Intel Code, to make, use, sell,
3260786Sps * offer to sell, and import the Covered Code and derivative works thereof
3360786Sps * solely to the minimum extent necessary to exercise the above copyright
3460786Sps * license, and in no event shall the patent license extend to any additions
3560786Sps * to or modifications of the Original Intel Code.  No other license or right
3660786Sps * is granted directly or by implication, estoppel or otherwise;
3760786Sps *
3860786Sps * The above copyright and patent license is granted only if the following
3960786Sps * conditions are met:
4060786Sps *
4160786Sps * 3. Conditions
4260786Sps *
4360786Sps * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4460786Sps * Redistribution of source code of any substantial portion of the Covered
4560786Sps * Code or modification with rights to further distribute source must include
4660786Sps * the above Copyright Notice, the above License, this list of Conditions,
4760786Sps * and the following Disclaimer and Export Compliance provision.  In addition,
4860786Sps * Licensee must cause all Covered Code to which Licensee contributes to
4960786Sps * contain a file documenting the changes Licensee made to create that Covered
5060786Sps * Code and the date of any change.  Licensee must include in that file the
5160786Sps * documentation of any changes made by any predecessor Licensee.  Licensee
5260786Sps * must include a prominent statement that the modification is derived,
5360786Sps * directly or indirectly, from Original Intel Code.
5460786Sps *
5560786Sps * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5660786Sps * Redistribution of source code of any substantial portion of the Covered
5760786Sps * Code or modification without rights to further distribute source must
5860786Sps * include the following Disclaimer and Export Compliance provision in the
5960786Sps * documentation and/or other materials provided with distribution.  In
6060786Sps * addition, Licensee may not authorize further sublicense of source of any
6160786Sps * portion of the Covered Code, and must include terms to the effect that the
6260786Sps * license from Licensee to its licensee is limited to the intellectual
6360786Sps * property embodied in the software Licensee provides to its licensee, and
6460786Sps * not to intellectual property embodied in modifications its licensee may
6560786Sps * make.
6660786Sps *
6760786Sps * 3.3. Redistribution of Executable. Redistribution in executable form of any
6860786Sps * substantial portion of the Covered Code or modification must reproduce the
6960786Sps * above Copyright Notice, and the following Disclaimer and Export Compliance
7060786Sps * provision in the documentation and/or other materials provided with the
7160786Sps * distribution.
7260786Sps *
7360786Sps * 3.4. Intel retains all right, title, and interest in and to the Original
7460786Sps * Intel Code.
7560786Sps *
7660786Sps * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7760786Sps * Intel shall be used in advertising or otherwise to promote the sale, use or
7860786Sps * other dealings in products derived from or relating to the Covered Code
7960786Sps * without prior written authorization from Intel.
8060786Sps *
8160786Sps * 4. Disclaimer and Export Compliance
8260786Sps *
8360786Sps * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8460786Sps * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8560786Sps * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8660786Sps * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8760786Sps * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8860786Sps * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8960786Sps * PARTICULAR PURPOSE.
9060786Sps *
9160786Sps * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9260786Sps * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9360786Sps * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9460786Sps * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9560786Sps * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9660786Sps * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9760786Sps * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9860786Sps * LIMITED REMEDY.
9960786Sps *
10060786Sps * 4.3. Licensee shall not export, either directly or indirectly, any of this
10160786Sps * software or system incorporating such software without first obtaining any
10260786Sps * required license or other approval from the U. S. Department of Commerce or
10360786Sps * any other agency or department of the United States Government.  In the
10460786Sps * event Licensee exports any such software from the United States or
10560786Sps * re-exports any such software from a foreign destination, Licensee shall
10660786Sps * ensure that the distribution and export/re-export of the software is in
10760786Sps * compliance with all laws, regulations, orders, or other restrictions of the
10860786Sps * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10960786Sps * any of its subsidiaries will export/re-export any technical data, process,
11060786Sps * software, or service, directly or indirectly, to any country for which the
11160786Sps * United States government or any agency thereof requires an export license,
11260786Sps * other governmental approval, or letter of assurance, without first obtaining
11360786Sps * such license, approval or letter.
11460786Sps *
11560786Sps *****************************************************************************/
11660786Sps
11760786Sps
11860786Sps#define __RSUTILS_C__
11960786Sps
12060786Sps#include "acpi.h"
12160786Sps#include "acnamesp.h"
12260786Sps#include "acresrc.h"
12360786Sps
12460786Sps
12560786Sps#define _COMPONENT          ACPI_RESOURCES
12660786Sps        ACPI_MODULE_NAME    ("rsutils")
12760786Sps
12860786Sps
12960786Sps/*******************************************************************************
13060786Sps *
13160786Sps * FUNCTION:    AcpiRsGetPrtMethodData
13260786Sps *
13360786Sps * PARAMETERS:  Handle          - a handle to the containing object
13460786Sps *              RetBuffer       - a pointer to a buffer structure for the
13560786Sps *                                  results
13660786Sps *
13760786Sps * RETURN:      Status
13860786Sps *
13960786Sps * DESCRIPTION: This function is called to get the _PRT value of an object
14060786Sps *              contained in an object specified by the handle passed in
14160786Sps *
14260786Sps *              If the function fails an appropriate status will be returned
14360786Sps *              and the contents of the callers buffer is undefined.
14460786Sps *
14560786Sps ******************************************************************************/
14660786Sps
14760786SpsACPI_STATUS
14860786SpsAcpiRsGetPrtMethodData (
14960786Sps    ACPI_HANDLE             Handle,
15060786Sps    ACPI_BUFFER             *RetBuffer)
15160786Sps{
15260786Sps    ACPI_OPERAND_OBJECT     *ObjDesc;
15360786Sps    ACPI_STATUS             Status;
15460786Sps
15560786Sps
15660786Sps    ACPI_FUNCTION_TRACE ("RsGetPrtMethodData");
15760786Sps
15860786Sps
15960786Sps    /* Parameters guaranteed valid by caller */
16060786Sps
16160786Sps    /*
16260786Sps     *  Execute the method, no parameters
16360786Sps     */
16460786Sps    Status = AcpiNsEvaluateRelative (Handle, "_PRT", NULL, &ObjDesc);
16560786Sps    if (ACPI_FAILURE (Status))
16660786Sps    {
16760786Sps        return_ACPI_STATUS (Status);
16860786Sps    }
16960786Sps
17060786Sps    if (!ObjDesc)
17160786Sps    {
17260786Sps        /* Return object is required */
17360786Sps
17460786Sps        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object was returned from _PRT\n"));
17560786Sps        return_ACPI_STATUS (AE_TYPE);
17660786Sps    }
17760786Sps
17860786Sps    /*
17960786Sps     * The return object must be a package, so check the parameters.  If the
18060786Sps     * return object is not a package, then the underlying AML code is corrupt
18160786Sps     * or improperly written.
18260786Sps     */
18360786Sps    if (ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_PACKAGE)
18460786Sps    {
18560786Sps        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "_PRT did not return a Package, returned %s\n",
18660786Sps                AcpiUtGetObjectTypeName (ObjDesc)));
18760786Sps        Status = AE_AML_OPERAND_TYPE;
18860786Sps        goto Cleanup;
18960786Sps    }
19060786Sps
19160786Sps    /*
19260786Sps     * Create a resource linked list from the byte stream buffer that comes
19360786Sps     * back from the _CRS method execution.
19460786Sps     */
19560786Sps    Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer);
19660786Sps
19760786Sps    /* On exit, we must delete the object returned by EvaluateObject */
19860786Sps
19960786SpsCleanup:
20060786Sps
20160786Sps    AcpiUtRemoveReference (ObjDesc);
20260786Sps    return_ACPI_STATUS (Status);
20360786Sps}
20460786Sps
20560786Sps
20660786Sps/*******************************************************************************
20760786Sps *
20860786Sps * FUNCTION:    AcpiRsGetCrsMethodData
20960786Sps *
21060786Sps * PARAMETERS:  Handle          - a handle to the containing object
21160786Sps *              RetBuffer       - a pointer to a buffer structure for the
21260786Sps *                                  results
21360786Sps *
21460786Sps * RETURN:      Status
21560786Sps *
21660786Sps * DESCRIPTION: This function is called to get the _CRS value of an object
21760786Sps *              contained in an object specified by the handle passed in
21860786Sps *
21960786Sps *              If the function fails an appropriate status will be returned
22060786Sps *              and the contents of the callers buffer is undefined.
22160786Sps *
22260786Sps ******************************************************************************/
22360786Sps
22460786SpsACPI_STATUS
22560786SpsAcpiRsGetCrsMethodData (
22660786Sps    ACPI_HANDLE             Handle,
22760786Sps    ACPI_BUFFER             *RetBuffer)
22860786Sps{
22960786Sps    ACPI_OPERAND_OBJECT     *ObjDesc;
23060786Sps    ACPI_STATUS             Status;
23160786Sps
23260786Sps
23360786Sps    ACPI_FUNCTION_TRACE ("RsGetCrsMethodData");
23460786Sps
23560786Sps
23660786Sps    /* Parameters guaranteed valid by caller */
23760786Sps
23860786Sps    /*
23960786Sps     * Execute the method, no parameters
24060786Sps     */
24160786Sps    Status = AcpiNsEvaluateRelative (Handle, "_CRS", NULL, &ObjDesc);
24260786Sps    if (ACPI_FAILURE (Status))
24360786Sps    {
24460786Sps        return_ACPI_STATUS (Status);
24560786Sps    }
24660786Sps
24760786Sps    if (!ObjDesc)
24860786Sps    {
24960786Sps        /* Return object is required */
25060786Sps
25160786Sps        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object was returned from _CRS\n"));
25260786Sps        return_ACPI_STATUS (AE_TYPE);
25360786Sps    }
25460786Sps
25560786Sps    /*
25660786Sps     * The return object will be a buffer, but check the
25760786Sps     * parameters.  If the return object is not a buffer,
25860786Sps     * then the underlying AML code is corrupt or improperly
25960786Sps     * written.
26060786Sps     */
26160786Sps    if (ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_BUFFER)
26260786Sps    {
26360786Sps        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "_CRS did not return a Buffer, returned %s\n",
26460786Sps                AcpiUtGetObjectTypeName (ObjDesc)));
26560786Sps        Status = AE_AML_OPERAND_TYPE;
26660786Sps        goto Cleanup;
26760786Sps    }
26860786Sps
26960786Sps    /*
27060786Sps     * Make the call to create a resource linked list from the
27160786Sps     * byte stream buffer that comes back from the _CRS method
27260786Sps     * execution.
27360786Sps     */
27460786Sps    Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
27560786Sps
27660786Sps    /* On exit, we must delete the object returned by evaluateObject */
27760786Sps
27860786SpsCleanup:
27960786Sps
28060786Sps    AcpiUtRemoveReference (ObjDesc);
28160786Sps    return_ACPI_STATUS (Status);
28260786Sps}
28360786Sps
28460786Sps
28560786Sps/*******************************************************************************
28660786Sps *
28760786Sps * FUNCTION:    AcpiRsGetPrsMethodData
28860786Sps *
28960786Sps * PARAMETERS:  Handle          - a handle to the containing object
29060786Sps *              RetBuffer       - a pointer to a buffer structure for the
29160786Sps *                                  results
29260786Sps *
29360786Sps * RETURN:      Status
29460786Sps *
29560786Sps * DESCRIPTION: This function is called to get the _PRS value of an object
29660786Sps *              contained in an object specified by the handle passed in
29760786Sps *
29860786Sps *              If the function fails an appropriate status will be returned
29960786Sps *              and the contents of the callers buffer is undefined.
30060786Sps *
30160786Sps ******************************************************************************/
30260786Sps
30360786SpsACPI_STATUS
30460786SpsAcpiRsGetPrsMethodData (
30560786Sps    ACPI_HANDLE             Handle,
30660786Sps    ACPI_BUFFER             *RetBuffer)
30760786Sps{
30860786Sps    ACPI_OPERAND_OBJECT     *ObjDesc;
30960786Sps    ACPI_STATUS             Status;
31060786Sps
31160786Sps
31260786Sps    ACPI_FUNCTION_TRACE ("RsGetPrsMethodData");
31360786Sps
31460786Sps
31560786Sps    /* Parameters guaranteed valid by caller */
31660786Sps
31760786Sps    /*
31860786Sps     * Execute the method, no parameters
31960786Sps     */
32060786Sps    Status = AcpiNsEvaluateRelative (Handle, "_PRS", NULL, &ObjDesc);
32160786Sps    if (ACPI_FAILURE (Status))
32260786Sps    {
32360786Sps        return_ACPI_STATUS (Status);
32460786Sps    }
32560786Sps
32660786Sps    if (!ObjDesc)
32760786Sps    {
32860786Sps        /* Return object is required */
32960786Sps
33060786Sps        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object was returned from _PRS\n"));
33160786Sps        return_ACPI_STATUS (AE_TYPE);
33260786Sps    }
33360786Sps
33460786Sps    /*
33560786Sps     * The return object will be a buffer, but check the
33660786Sps     * parameters.  If the return object is not a buffer,
33760786Sps     * then the underlying AML code is corrupt or improperly
33860786Sps     * written..
33960786Sps     */
34060786Sps    if (ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_BUFFER)
34160786Sps    {
34260786Sps        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "_PRS did not return a Buffer, returned %s\n",
34360786Sps                AcpiUtGetObjectTypeName (ObjDesc)));
34460786Sps        Status = AE_AML_OPERAND_TYPE;
34560786Sps        goto Cleanup;
34660786Sps    }
34760786Sps
34860786Sps    /*
34960786Sps     * Make the call to create a resource linked list from the
35060786Sps     * byte stream buffer that comes back from the _CRS method
35160786Sps     * execution.
35260786Sps     */
35360786Sps    Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
35460786Sps
35560786Sps    /* On exit, we must delete the object returned by evaluateObject */
35660786Sps
35760786SpsCleanup:
35860786Sps
35960786Sps    AcpiUtRemoveReference (ObjDesc);
36060786Sps    return_ACPI_STATUS (Status);
36160786Sps}
36260786Sps
36360786Sps
36460786Sps/*******************************************************************************
36560786Sps *
36660786Sps * FUNCTION:    AcpiRsSetSrsMethodData
36760786Sps *
36860786Sps * PARAMETERS:  Handle          - a handle to the containing object
36960786Sps *              InBuffer        - a pointer to a buffer structure of the
37060786Sps *                                  parameter
37160786Sps *
37260786Sps * RETURN:      Status
37360786Sps *
37460786Sps * DESCRIPTION: This function is called to set the _SRS of an object contained
37560786Sps *              in an object specified by the handle passed in
37660786Sps *
37760786Sps *              If the function fails an appropriate status will be returned
37860786Sps *              and the contents of the callers buffer is undefined.
37960786Sps *
38060786Sps ******************************************************************************/
38160786Sps
38260786SpsACPI_STATUS
38360786SpsAcpiRsSetSrsMethodData (
38460786Sps    ACPI_HANDLE             Handle,
38560786Sps    ACPI_BUFFER             *InBuffer)
38660786Sps{
38760786Sps    ACPI_OPERAND_OBJECT     *Params[2];
38860786Sps    ACPI_STATUS             Status;
38960786Sps    ACPI_BUFFER             Buffer;
39060786Sps
39160786Sps
39260786Sps    ACPI_FUNCTION_TRACE ("RsSetSrsMethodData");
39360786Sps
39460786Sps
39560786Sps    /* Parameters guaranteed valid by caller */
39660786Sps
39760786Sps    /*
39860786Sps     * The InBuffer parameter will point to a linked list of
39960786Sps     * resource parameters.  It needs to be formatted into a
40060786Sps     * byte stream to be sent in as an input parameter to _SRS
40160786Sps     *
40260786Sps     * Convert the linked list into a byte stream
40360786Sps     */
40460786Sps    Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
40560786Sps    Status = AcpiRsCreateByteStream (InBuffer->Pointer, &Buffer);
40660786Sps    if (ACPI_FAILURE (Status))
40760786Sps    {
40860786Sps        return_ACPI_STATUS (Status);
40960786Sps    }
41060786Sps
41160786Sps    /*
41260786Sps     * Init the param object
41360786Sps     */
41460786Sps    Params[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
41560786Sps    if (!Params[0])
41660786Sps    {
41760786Sps        AcpiOsFree (Buffer.Pointer);
41860786Sps        return_ACPI_STATUS (AE_NO_MEMORY);
41960786Sps    }
42060786Sps
42160786Sps    /*
42260786Sps     * Set up the parameter object
42360786Sps     */
42460786Sps    Params[0]->Buffer.Length  = (UINT32) Buffer.Length;
42560786Sps    Params[0]->Buffer.Pointer = Buffer.Pointer;
42660786Sps    Params[0]->Common.Flags   = AOPOBJ_DATA_VALID;
42760786Sps    Params[1] = NULL;
42860786Sps
42960786Sps    /*
43060786Sps     * Execute the method, no return value
43160786Sps     */
43260786Sps    Status = AcpiNsEvaluateRelative (Handle, "_SRS", Params, NULL);
43360786Sps
43460786Sps    /*
43560786Sps     * Clean up and return the status from AcpiNsEvaluateRelative
43660786Sps     */
43760786Sps    AcpiUtRemoveReference (Params[0]);
43860786Sps    return_ACPI_STATUS (Status);
43960786Sps}
44060786Sps
44160786Sps