rscreate.c revision 114237
117658Sjulian/*******************************************************************************
217658Sjulian *
317658Sjulian * Module Name: rscreate - Create resource lists/tables
417658Sjulian *              $Revision: 64 $
517658Sjulian *
617658Sjulian ******************************************************************************/
717658Sjulian
817658Sjulian/******************************************************************************
917658Sjulian *
1017658Sjulian * 1. Copyright Notice
1117658Sjulian *
1217658Sjulian * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
1317658Sjulian * All rights reserved.
1417658Sjulian *
1517658Sjulian * 2. License
1617658Sjulian *
1717658Sjulian * 2.1. This is your license from Intel Corp. under its intellectual property
1817658Sjulian * rights.  You may have additional license terms from the party that provided
1917658Sjulian * you this software, covering your right to use that party's intellectual
2017658Sjulian * property rights.
2117658Sjulian *
2217658Sjulian * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2317658Sjulian * copy of the source code appearing in this file ("Covered Code") an
2417658Sjulian * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2517658Sjulian * base code distributed originally by Intel ("Original Intel Code") to copy,
2617658Sjulian * make derivatives, distribute, use and display any portion of the Covered
2717658Sjulian * Code in any form, with the right to sublicense such rights; and
2817658Sjulian *
2917658Sjulian * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3017658Sjulian * license (with the right to sublicense), under only those claims of Intel
3117658Sjulian * patents that are infringed by the Original Intel Code, to make, use, sell,
3217658Sjulian * offer to sell, and import the Covered Code and derivative works thereof
3317658Sjulian * solely to the minimum extent necessary to exercise the above copyright
3417658Sjulian * license, and in no event shall the patent license extend to any additions
3517658Sjulian * to or modifications of the Original Intel Code.  No other license or right
3617658Sjulian * is granted directly or by implication, estoppel or otherwise;
37116182Sobrien *
38116182Sobrien * The above copyright and patent license is granted only if the following
39116182Sobrien * conditions are met:
40131927Smarcel *
41106024Srwatson * 3. Conditions
4228976Sbde *
4328976Sbde * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44134649Sscottl * Redistribution of source code of any substantial portion of the Covered
4517658Sjulian * Code or modification with rights to further distribute source must include
4617658Sjulian * the above Copyright Notice, the above License, this list of Conditions,
4717658Sjulian * and the following Disclaimer and Export Compliance provision.  In addition,
4860041Sphk * Licensee must cause all Covered Code to which Licensee contributes to
4931275Sbde * contain a file documenting the changes Licensee made to create that Covered
5078767Sjhb * Code and the date of any change.  Licensee must include in that file the
5178767Sjhb * documentation of any changes made by any predecessor Licensee.  Licensee
5278767Sjhb * must include a prominent statement that the modification is derived,
53131927Smarcel * directly or indirectly, from Original Intel Code.
5417658Sjulian *
5555539Sluoqi * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56106024Srwatson * Redistribution of source code of any substantial portion of the Covered
5789601Ssobomax * Code or modification without rights to further distribute source must
5821776Sbde * include the following Disclaimer and Export Compliance provision in the
5978767Sjhb * documentation and/or other materials provided with distribution.  In
6078767Sjhb * addition, Licensee may not authorize further sublicense of source of any
6178767Sjhb * portion of the Covered Code, and must include terms to the effect that the
62137263Speter * license from Licensee to its licensee is limited to the intellectual
6378767Sjhb * property embodied in the software Licensee provides to its licensee, and
6417658Sjulian * not to intellectual property embodied in modifications its licensee may
6517658Sjulian * make.
6678767Sjhb *
6717658Sjulian * 3.3. Redistribution of Executable. Redistribution in executable form of any
68118990Smarcel * substantial portion of the Covered Code or modification must reproduce the
6994169Sphk * above Copyright Notice, and the following Disclaimer and Export Compliance
7091778Sjake * provision in the documentation and/or other materials provided with the
7117658Sjulian * distribution.
7217658Sjulian *
7317658Sjulian * 3.4. Intel retains all right, title, and interest in and to the Original
7417658Sjulian * Intel Code.
7517658Sjulian *
7617658Sjulian * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7717658Sjulian * Intel shall be used in advertising or otherwise to promote the sale, use or
7817658Sjulian * other dealings in products derived from or relating to the Covered Code
7917658Sjulian * without prior written authorization from Intel.
8017658Sjulian *
8117658Sjulian * 4. Disclaimer and Export Compliance
8217658Sjulian *
8317658Sjulian * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84131927Smarcel * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85131927Smarcel * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8642135Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8717658Sjulian * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8842135Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8917658Sjulian * PARTICULAR PURPOSE.
9017658Sjulian *
9146381Sbillf * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92103647Sjhb * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93131927Smarcel * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94103647Sjhb * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95103647Sjhb * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96103647Sjhb * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9717658Sjulian * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98103647Sjhb * LIMITED REMEDY.
99103647Sjhb *
100131927Smarcel * 4.3. Licensee shall not export, either directly or indirectly, any of this
10117658Sjulian * software or system incorporating such software without first obtaining any
102132506Srwatson * required license or other approval from the U. S. Department of Commerce or
10385202Speter * any other agency or department of the United States Government.  In the
10485202Speter * event Licensee exports any such software from the United States or
10585202Speter * re-exports any such software from a foreign destination, Licensee shall
10643436Smsmith * ensure that the distribution and export/re-export of the software is in
10743436Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10817658Sjulian * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10917658Sjulian * any of its subsidiaries will export/re-export any technical data, process,
11017658Sjulian * software, or service, directly or indirectly, to any country for which the
11117658Sjulian * United States government or any agency thereof requires an export license,
11217658Sjulian * other governmental approval, or letter of assurance, without first obtaining
11317658Sjulian * such license, approval or letter.
11493496Sphk *
11593496Sphk *****************************************************************************/
11667093Sps
117131927Smarcel
118131927Smarcel#define __RSCREATE_C__
119131927Smarcel
120131927Smarcel#include "acpi.h"
12165395Speter#include "acresrc.h"
12265395Speter#include "amlcode.h"
12365395Speter#include "acnamesp.h"
12465395Speter
12565395Speter#define _COMPONENT          ACPI_RESOURCES
12617658Sjulian        ACPI_MODULE_NAME    ("rscreate")
12750107Smsmith
128110859Salfred
12950107Smsmith/*******************************************************************************
13050107Smsmith *
131110859Salfred * FUNCTION:    AcpiRsCreateResourceList
132110859Salfred *
133110859Salfred * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource byte stream
134110859Salfred *              OutputBuffer            - Pointer to the user's buffer
135110859Salfred *
136110859Salfred * RETURN:      Status  - AE_OK if okay, else a valid ACPI_STATUS code
137110859Salfred *              If OutputBuffer is not large enough, OutputBufferLength
138110859Salfred *              indicates how large OutputBuffer should be, else it
139110859Salfred *              indicates how may UINT8 elements of OutputBuffer are valid.
14050107Smsmith *
14148868Sphk * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method
14250107Smsmith *              execution and parses the stream to create a linked list
14350107Smsmith *              of device resources.
14417658Sjulian *
14517658Sjulian ******************************************************************************/
14682749Sdillon
14782749SdillonACPI_STATUS
14817658SjulianAcpiRsCreateResourceList (
14982749Sdillon    ACPI_OPERAND_OBJECT     *ByteStreamBuffer,
15017658Sjulian    ACPI_BUFFER             *OutputBuffer)
15183366Sjulian{
15217658Sjulian
15317658Sjulian    ACPI_STATUS             Status;
15417658Sjulian    UINT8                   *ByteStreamStart;
155106024Srwatson    ACPI_SIZE               ListSizeNeeded = 0;
156106024Srwatson    UINT32                  ByteStreamBufferLength;
157106024Srwatson
158106024Srwatson
159106024Srwatson    ACPI_FUNCTION_TRACE ("RsCreateResourceList");
160106024Srwatson
161106024Srwatson
162106024Srwatson    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ByteStreamBuffer = %p\n",
16382749Sdillon        ByteStreamBuffer));
164106024Srwatson
165106024Srwatson    /*
16682749Sdillon     * Params already validated, so we don't re-validate here
16717658Sjulian     */
16817658Sjulian    ByteStreamBufferLength = ByteStreamBuffer->Buffer.Length;
16917658Sjulian    ByteStreamStart = ByteStreamBuffer->Buffer.Pointer;
17017658Sjulian
17117658Sjulian    /*
17265268Smsmith     * Pass the ByteStreamBuffer into a module that can calculate
17365268Smsmith     * the buffer size needed for the linked list
17417658Sjulian     */
17565268Smsmith    Status = AcpiRsGetListLength (ByteStreamStart, ByteStreamBufferLength,
17617658Sjulian                &ListSizeNeeded);
177110859Salfred
17865268Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n",
179110859Salfred        Status, (UINT32) ListSizeNeeded));
18017658Sjulian    if (ACPI_FAILURE (Status))
18117658Sjulian    {
18273913Sjhb        return_ACPI_STATUS (Status);
18317658Sjulian    }
18473913Sjhb
18517658Sjulian    /* Validate/Allocate/Clear caller buffer */
18617658Sjulian
18717658Sjulian    Status = AcpiUtInitializeBuffer (OutputBuffer, ListSizeNeeded);
18817658Sjulian    if (ACPI_FAILURE (Status))
18917658Sjulian    {
19017658Sjulian        return_ACPI_STATUS (Status);
19117658Sjulian    }
19217658Sjulian
19354233Sphk    /* Do the conversion */
19465395Speter
19554233Sphk    Status = AcpiRsByteStreamToList (ByteStreamStart, ByteStreamBufferLength,
19654233Sphk                    OutputBuffer->Pointer);
19754233Sphk    if (ACPI_FAILURE (Status))
19854233Sphk    {
19954233Sphk        return_ACPI_STATUS (Status);
20054233Sphk    }
20154233Sphk
20254233Sphk    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
20365764Sjhb            OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
20454233Sphk    return_ACPI_STATUS (AE_OK);
20554233Sphk}
20654233Sphk
20754233Sphk
20865764Sjhb/*******************************************************************************
20954233Sphk *
21054233Sphk * FUNCTION:    AcpiRsCreatePciRoutingTable
21154233Sphk *
21254233Sphk * PARAMETERS:  PackageObject           - Pointer to an ACPI_OPERAND_OBJECT
21365764Sjhb *                                        package
21454233Sphk *              OutputBuffer            - Pointer to the user's buffer
21554233Sphk *
21654233Sphk * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code.
21765764Sjhb *              If the OutputBuffer is too small, the error will be
21854233Sphk *              AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
21954233Sphk *              to the size buffer needed.
22094169Sphk *
22194169Sphk * DESCRIPTION: Takes the ACPI_OPERAND_OBJECT  package and creates a
22294169Sphk *              linked list of PCI interrupt descriptions
223110859Salfred *
224132412Sjulian * NOTE: It is the caller's responsibility to ensure that the start of the
225132412Sjulian * output buffer is aligned properly (if necessary).
226132412Sjulian *
227132412Sjulian ******************************************************************************/
228132412Sjulian
229132412SjulianACPI_STATUS
230132413SjulianAcpiRsCreatePciRoutingTable (
231132412Sjulian    ACPI_OPERAND_OBJECT     *PackageObject,
232132412Sjulian    ACPI_BUFFER             *OutputBuffer)
233132412Sjulian{
23494169Sphk    UINT8                   *Buffer;
235131927Smarcel    ACPI_OPERAND_OBJECT     **TopObjectList;
23694169Sphk    ACPI_OPERAND_OBJECT     **SubObjectList;
23794169Sphk    ACPI_OPERAND_OBJECT     *ObjDesc;
23894169Sphk    ACPI_SIZE               BufferSizeNeeded = 0;
23994169Sphk    UINT32                  NumberOfElements;
24017658Sjulian    UINT32                  Index;
241137329Snjl    ACPI_PCI_ROUTING_TABLE  *UserPrt;
24217658Sjulian    ACPI_NAMESPACE_NODE     *Node;
24331275Sbde    ACPI_STATUS             Status;
24465395Speter    ACPI_BUFFER             PathBuffer;
24517658Sjulian
246133763Struckman
24717658Sjulian    ACPI_FUNCTION_TRACE ("RsCreatePciRoutingTable");
248137266Speter
249137329Snjl
250137329Snjl    /* Params already validated, so we don't re-validate here */
251137329Snjl
252137329Snjl    /*
253137329Snjl     * Get the required buffer length
254137263Speter     */
255137263Speter    Status = AcpiRsGetPciRoutingTableLength (PackageObject,
256137263Speter                &BufferSizeNeeded);
257137263Speter    if (ACPI_FAILURE (Status))
258137263Speter    {
25965268Smsmith        return_ACPI_STATUS (Status);
26065268Smsmith    }
26165268Smsmith
26282119Sjhb    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "BufferSizeNeeded = %X\n",
263131927Smarcel        (UINT32) BufferSizeNeeded));
26482119Sjhb
26525164Speter    /* Validate/Allocate/Clear caller buffer */
26665395Speter
26770861Sjake    Status = AcpiUtInitializeBuffer (OutputBuffer, BufferSizeNeeded);
26825164Speter    if (ACPI_FAILURE (Status))
26927997Sjulian    {
27027997Sjulian        return_ACPI_STATUS (Status);
27127997Sjulian    }
27250107Smsmith
27327997Sjulian    /*
27427997Sjulian     * Loop through the ACPI_INTERNAL_OBJECTS - Each object
27527997Sjulian     * should be a package that in turn contains an
27627997Sjulian     * ACPI_INTEGER Address, a UINT8 Pin, a Name and a UINT8 SourceIndex.
27717658Sjulian     */
27817658Sjulian    TopObjectList    = PackageObject->Package.Elements;
27965707Sjasone    NumberOfElements = PackageObject->Package.Count;
280131481Sjhb    Buffer           = OutputBuffer->Pointer;
28165707Sjasone    UserPrt          = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer);
282131481Sjhb
28317658Sjulian    for (Index = 0; Index < NumberOfElements; Index++)
28417658Sjulian    {
28517658Sjulian        /*
28690361Sjulian         * Point UserPrt past this current structure
28717658Sjulian         *
28834266Sjulian         * NOTE: On the first iteration, UserPrt->Length will
28934266Sjulian         * be zero because we cleared the return buffer earlier
29034266Sjulian         */
29134266Sjulian        Buffer += UserPrt->Length;
29234266Sjulian        UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer);
29365707Sjasone
29417658Sjulian        /*
29517658Sjulian         * Fill in the Length field with the information we have at this point.
29648225Smckusick         * The minus four is to subtract the size of the UINT8 Source[4] member
29748225Smckusick         * because it is added below.
29817658Sjulian         */
29934266Sjulian        UserPrt->Length = (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
30034266Sjulian
30134266Sjulian        /*
30234266Sjulian         * Each element of the top-level package must also be a package
30317658Sjulian         */
30417658Sjulian        if (ACPI_GET_OBJECT_TYPE (*TopObjectList) != ACPI_TYPE_PACKAGE)
305133763Struckman        {
306133763Struckman            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
307136115Sphk                "(PRT[%X]) Need sub-package, found %s\n",
30817658Sjulian                Index, AcpiUtGetObjectTypeName (*TopObjectList)));
309133763Struckman            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
310133763Struckman        }
311133763Struckman
312133763Struckman        /* Each sub-package must be of length 4 */
313133763Struckman
31417658Sjulian        if ((*TopObjectList)->Package.Count != 4)
31565707Sjasone        {
31665707Sjasone            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
31765707Sjasone                "(PRT[%X]) Need package of length 4, found length %d\n",
31890361Sjulian                Index, (*TopObjectList)->Package.Count));
319131481Sjhb            return_ACPI_STATUS (AE_AML_PACKAGE_LIMIT);
320131481Sjhb        }
321131481Sjhb
322131481Sjhb        /*
323131481Sjhb         * Dereference the sub-package.
324131481Sjhb         * The SubObjectList will now point to an array of the four IRQ
325131481Sjhb         * elements: [Address, Pin, Source, SourceIndex]
32634266Sjulian         */
327131481Sjhb        SubObjectList = (*TopObjectList)->Package.Elements;
328131481Sjhb
329131481Sjhb        /*
330131481Sjhb         * 1) First subobject: Dereference the PRT.Address
331131481Sjhb         */
332131481Sjhb        ObjDesc = SubObjectList[0];
333131481Sjhb        if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_INTEGER)
334131481Sjhb        {
335131481Sjhb            UserPrt->Address = ObjDesc->Integer.Value;
336131481Sjhb        }
337131481Sjhb        else
338131481Sjhb        {
339131481Sjhb            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
340131481Sjhb                "(PRT[%X].Address) Need Integer, found %s\n",
341131481Sjhb                Index, AcpiUtGetObjectTypeName (ObjDesc)));
34217658Sjulian            return_ACPI_STATUS (AE_BAD_DATA);
343133418Snjl        }
34441137Smsmith
34541137Smsmith        /*
34641137Smsmith         * 2) Second subobject: Dereference the PRT.Pin
34741137Smsmith         */
34841137Smsmith        ObjDesc = SubObjectList[1];
34941137Smsmith        if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_INTEGER)
35048225Smckusick        {
35148225Smckusick            UserPrt->Pin = (UINT32) ObjDesc->Integer.Value;
352137186Sphk        }
353137186Sphk        else
354130640Sphk        {
35553452Sphk            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
35648225Smckusick                "(PRT[%X].Pin) Need Integer, found %s\n",
35753023Sphk                Index, AcpiUtGetObjectTypeName (ObjDesc)));
35853023Sphk            return_ACPI_STATUS (AE_BAD_DATA);
359137186Sphk        }
36053023Sphk
36153023Sphk        /*
36253023Sphk         * 3) Third subobject: Dereference the PRT.SourceName
363137186Sphk         */
364137186Sphk        ObjDesc = SubObjectList[2];
36553023Sphk        switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
36653023Sphk        {
36753023Sphk        case ACPI_TYPE_LOCAL_REFERENCE:
36846568Speter
36941137Smsmith            if (ObjDesc->Reference.Opcode != AML_INT_NAMEPATH_OP)
37017658Sjulian            {
37117658Sjulian                ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
37217658Sjulian                    "(PRT[%X].Source) Need name, found reference op %X\n",
37317658Sjulian                    Index, ObjDesc->Reference.Opcode));
37417658Sjulian                return_ACPI_STATUS (AE_BAD_DATA);
375133763Struckman            }
37617658Sjulian
37717658Sjulian            Node = ObjDesc->Reference.Node;
378133763Struckman
379133763Struckman            /* Use *remaining* length of the buffer as max for pathname */
38017658Sjulian
38117658Sjulian            PathBuffer.Length = OutputBuffer->Length -
38217658Sjulian                                (UINT32) ((UINT8 *) UserPrt->Source -
38317658Sjulian                                (UINT8 *) OutputBuffer->Pointer);
38417658Sjulian            PathBuffer.Pointer = UserPrt->Source;
38517658Sjulian
38639237Sgibbs            Status = AcpiNsHandleToPathname ((ACPI_HANDLE) Node, &PathBuffer);
38717658Sjulian
38827997Sjulian            UserPrt->Length += (UINT32) ACPI_STRLEN (UserPrt->Source) + 1; /* include null terminator */
38954233Sphk            break;
39054233Sphk
39127997Sjulian
39227997Sjulian        case ACPI_TYPE_STRING:
39327997Sjulian
39427997Sjulian            ACPI_STRCPY (UserPrt->Source, ObjDesc->String.Pointer);
39550107Smsmith
396137329Snjl            /* Add to the Length field the length of the string (add 1 for terminator) */
397137329Snjl
39839237Sgibbs            UserPrt->Length += ObjDesc->String.Length + 1;
399137329Snjl            break;
400132412Sjulian
40194169Sphk
40239237Sgibbs        case ACPI_TYPE_INTEGER:
40339237Sgibbs            /*
40450107Smsmith             * If this is a number, then the Source Name is NULL, since the
40539237Sgibbs             * entire buffer was zeroed out, we can leave this alone.
40650107Smsmith             *
40750107Smsmith             * Add to the Length field the length of the UINT32 NULL
40850107Smsmith             */
40950107Smsmith            UserPrt->Length += sizeof (UINT32);
41050107Smsmith            break;
41150107Smsmith
41250107Smsmith
41350107Smsmith        default:
41450107Smsmith
41550107Smsmith           ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
416110859Salfred               "(PRT[%X].Source) Need Ref/String/Integer, found %s\n",
41717658Sjulian                Index, AcpiUtGetObjectTypeName (ObjDesc)));
41817658Sjulian           return_ACPI_STATUS (AE_BAD_DATA);
41917658Sjulian        }
42017658Sjulian
42119274Sjulian        /* Now align the current length */
42219274Sjulian
42319274Sjulian        UserPrt->Length = ACPI_ROUND_UP_TO_64BITS (UserPrt->Length);
42419274Sjulian
42519274Sjulian        /*
42639237Sgibbs         * 4) Fourth subobject: Dereference the PRT.SourceIndex
42719274Sjulian         */
42819274Sjulian        ObjDesc = SubObjectList[3];
42950107Smsmith        if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_INTEGER)
43050107Smsmith        {
43117658Sjulian            UserPrt->SourceIndex = (UINT32) ObjDesc->Integer.Value;
43250107Smsmith        }
43350107Smsmith        else
43450107Smsmith        {
43550107Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
43650107Smsmith                "(PRT[%X].SourceIndex) Need Integer, found %s\n",
43750107Smsmith                Index, AcpiUtGetObjectTypeName (ObjDesc)));
43850107Smsmith            return_ACPI_STATUS (AE_BAD_DATA);
43950107Smsmith        }
44050107Smsmith
44150107Smsmith        /* Point to the next ACPI_OPERAND_OBJECT in the top level package */
44239237Sgibbs
44339237Sgibbs        TopObjectList++;
44439237Sgibbs    }
44539237Sgibbs
44639237Sgibbs    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
44739237Sgibbs            OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
44839237Sgibbs    return_ACPI_STATUS (AE_OK);
44939237Sgibbs}
45039237Sgibbs
45139237Sgibbs
45239237Sgibbs/*******************************************************************************
45317658Sjulian *
45439237Sgibbs * FUNCTION:    AcpiRsCreateByteStream
45550107Smsmith *
45617658Sjulian * PARAMETERS:  LinkedListBuffer        - Pointer to the resource linked list
45739237Sgibbs *              OutputBuffer            - Pointer to the user's buffer
45850107Smsmith *
45917658Sjulian * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code.
46089522Snik *              If the OutputBuffer is too small, the error will be
46189522Snik *              AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
46239237Sgibbs *              to the size buffer needed.
46317658Sjulian *
46450107Smsmith * DESCRIPTION: Takes the linked list of device resources and
46550107Smsmith *              creates a bytestream to be used as input for the
46650107Smsmith *              _SRS control method.
46750107Smsmith *
46850107Smsmith ******************************************************************************/
46950107Smsmith
47050107SmsmithACPI_STATUS
47150107SmsmithAcpiRsCreateByteStream (
472110859Salfred    ACPI_RESOURCE           *LinkedListBuffer,
47317658Sjulian    ACPI_BUFFER             *OutputBuffer)
47417658Sjulian{
47517677Sjulian    ACPI_STATUS             Status;
47617658Sjulian    ACPI_SIZE               ByteStreamSizeNeeded = 0;
47750107Smsmith
47817658Sjulian
47917658Sjulian    ACPI_FUNCTION_TRACE ("RsCreateByteStream");
48075570Sjhb
481101155Sjhb
48275570Sjhb    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "LinkedListBuffer = %p\n",
48375570Sjhb        LinkedListBuffer));
48417658Sjulian
48517658Sjulian    /*
48617658Sjulian     * Params already validated, so we don't re-validate here
48717658Sjulian     *
48882749Sdillon     * Pass the LinkedListBuffer into a module that calculates
48982749Sdillon     * the buffer size needed for the byte stream.
49017658Sjulian     */
49117658Sjulian    Status = AcpiRsGetByteStreamLength (LinkedListBuffer,
492130164Sphk                &ByteStreamSizeNeeded);
49317658Sjulian
494100209Sgallatin    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ByteStreamSizeNeeded=%X, %s\n",
495103647Sjhb        (UINT32) ByteStreamSizeNeeded, AcpiFormatException (Status)));
49617658Sjulian    if (ACPI_FAILURE (Status))
49738874Sache    {
49817658Sjulian        return_ACPI_STATUS (Status);
49965557Sjasone    }
50082115Sjhb
50182115Sjhb    /* Validate/Allocate/Clear caller buffer */
502101155Sjhb
503101155Sjhb    Status = AcpiUtInitializeBuffer (OutputBuffer, ByteStreamSizeNeeded);
50482115Sjhb    if (ACPI_FAILURE (Status))
50582115Sjhb    {
506101155Sjhb        return_ACPI_STATUS (Status);
507101155Sjhb    }
508101155Sjhb
509101155Sjhb    /* Do the conversion */
510101155Sjhb
51165557Sjasone    Status = AcpiRsListToByteStream (LinkedListBuffer, ByteStreamSizeNeeded,
51265557Sjasone                    OutputBuffer->Pointer);
51317658Sjulian    if (ACPI_FAILURE (Status))
514103647Sjhb    {
51517658Sjulian        return_ACPI_STATUS (Status);
51617658Sjulian    }
517103647Sjhb
51817658Sjulian    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
519103647Sjhb            OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
520103647Sjhb    return_ACPI_STATUS (AE_OK);
52117658Sjulian}
52217658Sjulian
523116398Siedowse