rsutils.c revision 91116
167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: rsutils - Utilities for the resource manager
491116Smsmith *              $Revision: 29 $
567754Smsmith *
667754Smsmith ******************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
1291116Smsmith * Some or all of this work - Copyright (c) 1999 - 2002, 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
11867754Smsmith#define __RSUTILS_C__
11967754Smsmith
12067754Smsmith#include "acpi.h"
12167754Smsmith#include "acnamesp.h"
12267754Smsmith#include "acresrc.h"
12367754Smsmith
12467754Smsmith
12577424Smsmith#define _COMPONENT          ACPI_RESOURCES
12691116Smsmith        ACPI_MODULE_NAME    ("rsutils")
12767754Smsmith
12867754Smsmith
12967754Smsmith/*******************************************************************************
13067754Smsmith *
13167754Smsmith * FUNCTION:    AcpiRsGetPrtMethodData
13267754Smsmith *
13367754Smsmith * PARAMETERS:  Handle          - a handle to the containing object
13467754Smsmith *              RetBuffer       - a pointer to a buffer structure for the
13567754Smsmith *                                  results
13667754Smsmith *
13777424Smsmith * RETURN:      Status
13867754Smsmith *
13967754Smsmith * DESCRIPTION: This function is called to get the _PRT value of an object
14067754Smsmith *              contained in an object specified by the handle passed in
14167754Smsmith *
14267754Smsmith *              If the function fails an appropriate status will be returned
14367754Smsmith *              and the contents of the callers buffer is undefined.
14467754Smsmith *
14567754Smsmith ******************************************************************************/
14667754Smsmith
14767754SmsmithACPI_STATUS
14867754SmsmithAcpiRsGetPrtMethodData (
14967754Smsmith    ACPI_HANDLE             Handle,
15067754Smsmith    ACPI_BUFFER             *RetBuffer)
15167754Smsmith{
15267754Smsmith    ACPI_OPERAND_OBJECT     *RetObj;
15367754Smsmith    ACPI_STATUS             Status;
15467754Smsmith
15567754Smsmith
15691116Smsmith    ACPI_FUNCTION_TRACE ("RsGetPrtMethodData");
15767754Smsmith
15867754Smsmith
15991116Smsmith    /* Parameters guaranteed valid by caller */
16067754Smsmith
16167754Smsmith    /*
16267754Smsmith     *  Execute the method, no parameters
16367754Smsmith     */
16467754Smsmith    Status = AcpiNsEvaluateRelative (Handle, "_PRT", NULL, &RetObj);
16567754Smsmith    if (ACPI_FAILURE (Status))
16667754Smsmith    {
16767754Smsmith        return_ACPI_STATUS (Status);
16867754Smsmith    }
16967754Smsmith
17067754Smsmith    if (!RetObj)
17167754Smsmith    {
17267754Smsmith        /* Return object is required */
17367754Smsmith
17482367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object was returned from _PRT\n"));
17567754Smsmith        return_ACPI_STATUS (AE_TYPE);
17667754Smsmith    }
17767754Smsmith
17867754Smsmith    /*
17991116Smsmith     * The return object will be a package, so check the parameters.  If the
18091116Smsmith     * return object is not a package, then the underlying AML code is corrupt
18191116Smsmith     * or improperly written.
18267754Smsmith     */
18367754Smsmith    if (ACPI_TYPE_PACKAGE != RetObj->Common.Type)
18467754Smsmith    {
18591116Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "_PRT did not return a Package, returned %s\n",
18691116Smsmith                AcpiUtGetTypeName (RetObj->Common.Type)));
18767754Smsmith        Status = AE_AML_OPERAND_TYPE;
18867754Smsmith        goto Cleanup;
18967754Smsmith    }
19067754Smsmith
19167754Smsmith    /*
19291116Smsmith     * Create a resource linked list from the byte stream buffer that comes
19391116Smsmith     * back from the _CRS method execution.
19467754Smsmith     */
19591116Smsmith    Status = AcpiRsCreatePciRoutingTable (RetObj, RetBuffer);
19667754Smsmith
19791116Smsmith    /* On exit, we must delete the object returned by EvaluateObject */
19867754Smsmith
19967754SmsmithCleanup:
20067754Smsmith
20177424Smsmith    AcpiUtRemoveReference (RetObj);
20267754Smsmith    return_ACPI_STATUS (Status);
20367754Smsmith}
20467754Smsmith
20567754Smsmith
20667754Smsmith/*******************************************************************************
20767754Smsmith *
20867754Smsmith * FUNCTION:    AcpiRsGetCrsMethodData
20967754Smsmith *
21067754Smsmith * PARAMETERS:  Handle          - a handle to the containing object
21167754Smsmith *              RetBuffer       - a pointer to a buffer structure for the
21267754Smsmith *                                  results
21367754Smsmith *
21477424Smsmith * RETURN:      Status
21567754Smsmith *
21667754Smsmith * DESCRIPTION: This function is called to get the _CRS value of an object
21767754Smsmith *              contained in an object specified by the handle passed in
21867754Smsmith *
21967754Smsmith *              If the function fails an appropriate status will be returned
22067754Smsmith *              and the contents of the callers buffer is undefined.
22167754Smsmith *
22267754Smsmith ******************************************************************************/
22367754Smsmith
22467754SmsmithACPI_STATUS
22567754SmsmithAcpiRsGetCrsMethodData (
22667754Smsmith    ACPI_HANDLE             Handle,
22767754Smsmith    ACPI_BUFFER             *RetBuffer)
22867754Smsmith{
22967754Smsmith    ACPI_OPERAND_OBJECT     *RetObj;
23067754Smsmith    ACPI_STATUS             Status;
23167754Smsmith
23267754Smsmith
23391116Smsmith    ACPI_FUNCTION_TRACE ("RsGetCrsMethodData");
23467754Smsmith
23567754Smsmith
23691116Smsmith    /* Parameters guaranteed valid by caller */
23767754Smsmith
23867754Smsmith    /*
23991116Smsmith     * Execute the method, no parameters
24067754Smsmith     */
24167754Smsmith    Status = AcpiNsEvaluateRelative (Handle, "_CRS", NULL, &RetObj);
24267754Smsmith    if (ACPI_FAILURE (Status))
24367754Smsmith    {
24467754Smsmith        return_ACPI_STATUS (Status);
24567754Smsmith    }
24667754Smsmith
24767754Smsmith    if (!RetObj)
24867754Smsmith    {
24967754Smsmith        /* Return object is required */
25067754Smsmith
25182367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object was returned from _CRS\n"));
25267754Smsmith        return_ACPI_STATUS (AE_TYPE);
25367754Smsmith    }
25467754Smsmith
25567754Smsmith    /*
25667754Smsmith     * The return object will be a buffer, but check the
25791116Smsmith     * parameters.  If the return object is not a buffer,
25891116Smsmith     * then the underlying AML code is corrupt or improperly
25991116Smsmith     * written.
26067754Smsmith     */
26167754Smsmith    if (ACPI_TYPE_BUFFER != RetObj->Common.Type)
26267754Smsmith    {
26391116Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "_CRS did not return a Buffer, returned %s\n",
26491116Smsmith                AcpiUtGetTypeName (RetObj->Common.Type)));
26567754Smsmith        Status = AE_AML_OPERAND_TYPE;
26667754Smsmith        goto Cleanup;
26767754Smsmith    }
26867754Smsmith
26967754Smsmith    /*
27067754Smsmith     * Make the call to create a resource linked list from the
27191116Smsmith     * byte stream buffer that comes back from the _CRS method
27291116Smsmith     * execution.
27367754Smsmith     */
27491116Smsmith    Status = AcpiRsCreateResourceList (RetObj, RetBuffer);
27567754Smsmith
27667754Smsmith    /* On exit, we must delete the object returned by evaluateObject */
27767754Smsmith
27867754SmsmithCleanup:
27967754Smsmith
28077424Smsmith    AcpiUtRemoveReference (RetObj);
28167754Smsmith    return_ACPI_STATUS (Status);
28267754Smsmith}
28367754Smsmith
28467754Smsmith
28567754Smsmith/*******************************************************************************
28667754Smsmith *
28767754Smsmith * FUNCTION:    AcpiRsGetPrsMethodData
28867754Smsmith *
28967754Smsmith * PARAMETERS:  Handle          - a handle to the containing object
29067754Smsmith *              RetBuffer       - a pointer to a buffer structure for the
29167754Smsmith *                                  results
29267754Smsmith *
29377424Smsmith * RETURN:      Status
29467754Smsmith *
29567754Smsmith * DESCRIPTION: This function is called to get the _PRS value of an object
29667754Smsmith *              contained in an object specified by the handle passed in
29767754Smsmith *
29867754Smsmith *              If the function fails an appropriate status will be returned
29967754Smsmith *              and the contents of the callers buffer is undefined.
30067754Smsmith *
30167754Smsmith ******************************************************************************/
30267754Smsmith
30367754SmsmithACPI_STATUS
30467754SmsmithAcpiRsGetPrsMethodData (
30567754Smsmith    ACPI_HANDLE             Handle,
30667754Smsmith    ACPI_BUFFER             *RetBuffer)
30767754Smsmith{
30867754Smsmith    ACPI_OPERAND_OBJECT     *RetObj;
30967754Smsmith    ACPI_STATUS             Status;
31067754Smsmith
31167754Smsmith
31291116Smsmith    ACPI_FUNCTION_TRACE ("RsGetPrsMethodData");
31367754Smsmith
31467754Smsmith
31591116Smsmith    /* Parameters guaranteed valid by caller */
31667754Smsmith
31767754Smsmith    /*
31891116Smsmith     * Execute the method, no parameters
31967754Smsmith     */
32067754Smsmith    Status = AcpiNsEvaluateRelative (Handle, "_PRS", NULL, &RetObj);
32167754Smsmith    if (ACPI_FAILURE (Status))
32267754Smsmith    {
32367754Smsmith        return_ACPI_STATUS (Status);
32467754Smsmith    }
32567754Smsmith
32667754Smsmith    if (!RetObj)
32767754Smsmith    {
32867754Smsmith        /* Return object is required */
32967754Smsmith
33082367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object was returned from _PRS\n"));
33167754Smsmith        return_ACPI_STATUS (AE_TYPE);
33267754Smsmith    }
33367754Smsmith
33467754Smsmith    /*
33567754Smsmith     * The return object will be a buffer, but check the
33691116Smsmith     * parameters.  If the return object is not a buffer,
33791116Smsmith     * then the underlying AML code is corrupt or improperly
33891116Smsmith     * written..
33967754Smsmith     */
34067754Smsmith    if (ACPI_TYPE_BUFFER != RetObj->Common.Type)
34167754Smsmith    {
34291116Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "_PRS did not return a Buffer, returned %s\n",
34391116Smsmith                AcpiUtGetTypeName (RetObj->Common.Type)));
34467754Smsmith        Status = AE_AML_OPERAND_TYPE;
34567754Smsmith        goto Cleanup;
34667754Smsmith    }
34767754Smsmith
34867754Smsmith    /*
34967754Smsmith     * Make the call to create a resource linked list from the
35091116Smsmith     * byte stream buffer that comes back from the _CRS method
35191116Smsmith     * execution.
35267754Smsmith     */
35391116Smsmith    Status = AcpiRsCreateResourceList (RetObj, RetBuffer);
35467754Smsmith
35567754Smsmith    /* On exit, we must delete the object returned by evaluateObject */
35667754Smsmith
35767754SmsmithCleanup:
35867754Smsmith
35977424Smsmith    AcpiUtRemoveReference (RetObj);
36067754Smsmith    return_ACPI_STATUS (Status);
36167754Smsmith}
36267754Smsmith
36367754Smsmith
36467754Smsmith/*******************************************************************************
36567754Smsmith *
36667754Smsmith * FUNCTION:    AcpiRsSetSrsMethodData
36767754Smsmith *
36867754Smsmith * PARAMETERS:  Handle          - a handle to the containing object
36967754Smsmith *              InBuffer        - a pointer to a buffer structure of the
37067754Smsmith *                                  parameter
37167754Smsmith *
37277424Smsmith * RETURN:      Status
37367754Smsmith *
37467754Smsmith * DESCRIPTION: This function is called to set the _SRS of an object contained
37567754Smsmith *              in an object specified by the handle passed in
37667754Smsmith *
37767754Smsmith *              If the function fails an appropriate status will be returned
37867754Smsmith *              and the contents of the callers buffer is undefined.
37967754Smsmith *
38067754Smsmith ******************************************************************************/
38167754Smsmith
38267754SmsmithACPI_STATUS
38367754SmsmithAcpiRsSetSrsMethodData (
38467754Smsmith    ACPI_HANDLE             Handle,
38567754Smsmith    ACPI_BUFFER             *InBuffer)
38667754Smsmith{
38767754Smsmith    ACPI_OPERAND_OBJECT     *Params[2];
38867754Smsmith    ACPI_STATUS             Status;
38991116Smsmith    ACPI_BUFFER             Buffer;
39067754Smsmith
39167754Smsmith
39291116Smsmith    ACPI_FUNCTION_TRACE ("RsSetSrsMethodData");
39367754Smsmith
39467754Smsmith
39591116Smsmith    /* Parameters guaranteed valid by caller */
39667754Smsmith
39767754Smsmith    /*
39867754Smsmith     * The InBuffer parameter will point to a linked list of
39977424Smsmith     * resource parameters.  It needs to be formatted into a
40091116Smsmith     * byte stream to be sent in as an input parameter to _SRS
40191116Smsmith     *
40291116Smsmith     * Convert the linked list into a byte stream
40367754Smsmith     */
40491116Smsmith    Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
40591116Smsmith    Status = AcpiRsCreateByteStream (InBuffer->Pointer, &Buffer);
40691116Smsmith    if (ACPI_FAILURE (Status))
40767754Smsmith    {
40867754Smsmith        return_ACPI_STATUS (Status);
40967754Smsmith    }
41067754Smsmith
41167754Smsmith    /*
41277424Smsmith     * Init the param object
41367754Smsmith     */
41484491Smsmith    Params[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
41584491Smsmith    if (!Params[0])
41684491Smsmith    {
41791116Smsmith        AcpiOsFree (Buffer.Pointer);
41891116Smsmith        return_ACPI_STATUS (AE_NO_MEMORY);
41984491Smsmith    }
42067754Smsmith
42167754Smsmith    /*
42291116Smsmith     * Set up the parameter object
42367754Smsmith     */
42491116Smsmith    Params[0]->Buffer.Length  = Buffer.Length;
42591116Smsmith    Params[0]->Buffer.Pointer = Buffer.Pointer;
42691116Smsmith    Params[1] = NULL;
42767754Smsmith
42867754Smsmith    /*
42977424Smsmith     * Execute the method, no return value
43067754Smsmith     */
43167754Smsmith    Status = AcpiNsEvaluateRelative (Handle, "_SRS", Params, NULL);
43267754Smsmith
43367754Smsmith    /*
43477424Smsmith     * Clean up and return the status from AcpiNsEvaluateRelative
43567754Smsmith     */
43691116Smsmith    AcpiUtRemoveReference (Params[0]);
43767754Smsmith    return_ACPI_STATUS (Status);
43867754Smsmith}
43967754Smsmith
440