rscreate.c revision 77424
1/*******************************************************************************
2 *
3 * Module Name: rscreate - Create resource lists/tables
4 *              $Revision: 33 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights.  You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code.  No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision.  In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change.  Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee.  Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution.  In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government.  In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117
118#define __RSCREATE_C__
119
120#include "acpi.h"
121#include "acresrc.h"
122#include "amlcode.h"
123#include "acnamesp.h"
124
125#define _COMPONENT          ACPI_RESOURCES
126        MODULE_NAME         ("rscreate")
127
128
129/*******************************************************************************
130 *
131 * FUNCTION:    AcpiRsCreateResourceList
132 *
133 * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource byte stream
134 *              OutputBuffer            - Pointer to the user's buffer
135 *              OutputBufferLength      - Pointer to the size of OutputBuffer
136 *
137 * RETURN:      Status  - AE_OK if okay, else a valid ACPI_STATUS code
138 *              If OutputBuffer is not large enough, OutputBufferLength
139 *              indicates how large OutputBuffer should be, else it
140 *              indicates how may UINT8 elements of OutputBuffer are valid.
141 *
142 * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method
143 *              execution and parses the stream to create a linked list
144 *              of device resources.
145 *
146 ******************************************************************************/
147
148ACPI_STATUS
149AcpiRsCreateResourceList (
150    ACPI_OPERAND_OBJECT     *ByteStreamBuffer,
151    UINT8                   *OutputBuffer,
152    UINT32                  *OutputBufferLength)
153{
154
155    ACPI_STATUS             Status;
156    UINT8                   *ByteStreamStart;
157    UINT32                  ListSizeNeeded = 0;
158    UINT32                  ByteStreamBufferLength;
159
160
161    FUNCTION_TRACE ("RsCreateResourceList");
162
163
164    DEBUG_PRINTP (VERBOSE_INFO, ("ByteStreamBuffer = %p\n", ByteStreamBuffer));
165
166    /*
167     * Params already validated, so we don't re-validate here
168     */
169
170    ByteStreamBufferLength = ByteStreamBuffer->Buffer.Length;
171    ByteStreamStart = ByteStreamBuffer->Buffer.Pointer;
172
173    /*
174     * Pass the ByteStreamBuffer into a module that can calculate
175     * the buffer size needed for the linked list
176     */
177    Status = AcpiRsCalculateListLength (ByteStreamStart, ByteStreamBufferLength,
178                &ListSizeNeeded);
179
180    DEBUG_PRINTP (VERBOSE_INFO, ("Status=%X ListSizeNeeded=%X\n",
181        Status, ListSizeNeeded));
182
183    /*
184     * Exit with the error passed back
185     */
186    if (ACPI_FAILURE (Status))
187    {
188        return_ACPI_STATUS (Status);
189    }
190
191    /*
192     * If the linked list will fit into the available buffer
193     * call to fill in the list
194     */
195
196    if (ListSizeNeeded <= *OutputBufferLength)
197    {
198        /*
199         * Zero out the return buffer before proceeding
200         */
201        MEMSET (OutputBuffer, 0x00, *OutputBufferLength);
202
203        Status = AcpiRsByteStreamToList (ByteStreamStart, ByteStreamBufferLength,
204                    &OutputBuffer);
205
206        /*
207         * Exit with the error passed back
208         */
209        if (ACPI_FAILURE (Status))
210        {
211            return_ACPI_STATUS (Status);
212        }
213
214        DEBUG_PRINTP (VERBOSE_INFO, ("OutputBuffer = %p\n", OutputBuffer));
215    }
216
217    else
218    {
219        *OutputBufferLength = ListSizeNeeded;
220        return_ACPI_STATUS (AE_BUFFER_OVERFLOW);
221    }
222
223    *OutputBufferLength = ListSizeNeeded;
224    return_ACPI_STATUS (AE_OK);
225}
226
227
228/*******************************************************************************
229 *
230 * FUNCTION:    AcpiRsCreatePciRoutingTable
231 *
232 * PARAMETERS:  PackageObject           - Pointer to an ACPI_OPERAND_OBJECT
233 *                                        package
234 *              OutputBuffer            - Pointer to the user's buffer
235 *              OutputBufferLength      - Size of OutputBuffer
236 *
237 * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code.
238 *              If the OutputBuffer is too small, the error will be
239 *              AE_BUFFER_OVERFLOW and OutputBufferLength will point
240 *              to the size buffer needed.
241 *
242 * DESCRIPTION: Takes the ACPI_OPERAND_OBJECT  package and creates a
243 *              linked list of PCI interrupt descriptions
244 *
245 ******************************************************************************/
246
247ACPI_STATUS
248AcpiRsCreatePciRoutingTable (
249    ACPI_OPERAND_OBJECT     *PackageObject,
250    UINT8                   *OutputBuffer,
251    UINT32                  *OutputBufferLength)
252{
253    UINT8                   *Buffer = OutputBuffer;
254    ACPI_OPERAND_OBJECT     **TopObjectList = NULL;
255    ACPI_OPERAND_OBJECT     **SubObjectList = NULL;
256    ACPI_OPERAND_OBJECT     *PackageElement = NULL;
257    UINT32                  BufferSizeNeeded = 0;
258    UINT32                  NumberOfElements = 0;
259    UINT32                  Index = 0;
260    PCI_ROUTING_TABLE       *UserPrt = NULL;
261    ACPI_NAMESPACE_NODE     *Node;
262    ACPI_STATUS             Status;
263
264
265    FUNCTION_TRACE ("RsCreatePciRoutingTable");
266
267
268    /*
269     * Params already validated, so we don't re-validate here
270     */
271
272    Status = AcpiRsCalculatePciRoutingTableLength (PackageObject,
273                &BufferSizeNeeded);
274
275    if (!ACPI_SUCCESS(Status))
276    {
277        return_ACPI_STATUS (Status);
278    }
279
280    DEBUG_PRINTP (VERBOSE_INFO, ("BufferSizeNeeded = %X\n", BufferSizeNeeded));
281
282    /*
283     * If the data will fit into the available buffer
284     * call to fill in the list
285     */
286    if (BufferSizeNeeded <= *OutputBufferLength)
287    {
288        /*
289         * Zero out the return buffer before proceeding
290         */
291        MEMSET (OutputBuffer, 0x00, *OutputBufferLength);
292
293        /*
294         * Loop through the ACPI_INTERNAL_OBJECTS - Each object should
295         * contain a UINT32 Address, a UINT8 Pin, a Name and a UINT8
296         * SourceIndex.
297         */
298        TopObjectList       = PackageObject->Package.Elements;
299        NumberOfElements    = PackageObject->Package.Count;
300        UserPrt             = (PCI_ROUTING_TABLE *) Buffer;
301
302
303        Buffer = ROUND_PTR_UP_TO_8 (Buffer, UINT8);
304
305        for (Index = 0; Index < NumberOfElements; Index++)
306        {
307            /*
308             * Point UserPrt past this current structure
309             *
310             * NOTE: On the first iteration, UserPrt->Length will
311             * be zero because we cleared the return buffer earlier
312             */
313            Buffer += UserPrt->Length;
314            UserPrt = (PCI_ROUTING_TABLE *) Buffer;
315
316
317            /*
318             * Fill in the Length field with the information we
319             * have at this point.
320             * The minus four is to subtract the size of the
321             * UINT8 Source[4] member because it is added below.
322             */
323            UserPrt->Length = (sizeof (PCI_ROUTING_TABLE) -4);
324
325            /*
326             * Dereference the sub-package
327             */
328            PackageElement = *TopObjectList;
329
330            /*
331             * The SubObjectList will now point to an array of
332             * the four IRQ elements: Address, Pin, Source and
333             * SourceIndex
334             */
335            SubObjectList = PackageElement->Package.Elements;
336
337            /*
338             * 1) First subobject:  Dereference the Address
339             */
340            if (ACPI_TYPE_INTEGER == (*SubObjectList)->Common.Type)
341            {
342                UserPrt->Address = (*SubObjectList)->Integer.Value;
343            }
344
345            else
346            {
347                DEBUG_PRINTP (ACPI_ERROR, ("Need Integer, found %s\n",
348                    AcpiUtGetTypeName ((*SubObjectList)->Common.Type)));
349                return_ACPI_STATUS (AE_BAD_DATA);
350            }
351
352            /*
353             * 2) Second subobject: Dereference the Pin
354             */
355            SubObjectList++;
356
357            if (ACPI_TYPE_INTEGER == (*SubObjectList)->Common.Type)
358            {
359                UserPrt->Pin = (UINT32) (*SubObjectList)->Integer.Value;
360            }
361
362            else
363            {
364                DEBUG_PRINTP (ACPI_ERROR, ("Need Integer, found %s\n",
365                    AcpiUtGetTypeName ((*SubObjectList)->Common.Type)));
366                return_ACPI_STATUS (AE_BAD_DATA);
367            }
368
369            /*
370             * 3) Third subobject: Dereference the Source Name
371             */
372            SubObjectList++;
373
374            switch ((*SubObjectList)->Common.Type)
375            {
376            case INTERNAL_TYPE_REFERENCE:
377
378                if ((*SubObjectList)->Reference.Opcode != AML_INT_NAMEPATH_OP)
379                {
380                   DEBUG_PRINTP (ACPI_ERROR, ("Need name, found reference op %X\n",
381                        (*SubObjectList)->Reference.Opcode));
382                    return_ACPI_STATUS (AE_BAD_DATA);
383                }
384
385                Node = (*SubObjectList)->Reference.Node;
386
387                /* TBD: use *remaining* length of the buffer! */
388
389                Status = AcpiNsHandleToPathname ((ACPI_HANDLE *) Node,
390                            OutputBufferLength, UserPrt->Source);
391
392                UserPrt->Length += STRLEN (UserPrt->Source) + 1; /* include null terminator */
393                break;
394
395
396            case ACPI_TYPE_STRING:
397
398                STRCPY (UserPrt->Source,
399                      (*SubObjectList)->String.Pointer);
400
401                /*
402                 * Add to the Length field the length of the string
403                 */
404                UserPrt->Length += (*SubObjectList)->String.Length;
405                break;
406
407
408            case ACPI_TYPE_INTEGER:
409                /*
410                 * If this is a number, then the Source Name
411                 * is NULL, since the entire buffer was zeroed
412                 * out, we can leave this alone.
413                 */
414                /*
415                 * Add to the Length field the length of
416                 * the UINT32 NULL
417                 */
418                UserPrt->Length += sizeof (UINT32);
419                break;
420
421
422            default:
423
424               DEBUG_PRINTP (ACPI_ERROR, ("Need Integer, found %s\n",
425                    AcpiUtGetTypeName ((*SubObjectList)->Common.Type)));
426               return_ACPI_STATUS (AE_BAD_DATA);
427               break;
428            }
429
430            /* Now align the current length */
431
432            UserPrt->Length = ROUND_UP_TO_64BITS (UserPrt->Length);
433
434            /*
435             * 4) Fourth subobject: Dereference the Source Index
436             */
437            SubObjectList++;
438
439            if (ACPI_TYPE_INTEGER == (*SubObjectList)->Common.Type)
440            {
441                UserPrt->SourceIndex = (UINT32) (*SubObjectList)->Integer.Value;
442            }
443
444            else
445            {
446                DEBUG_PRINTP (ACPI_ERROR, ("Need Integer, found %s\n",
447                    AcpiUtGetTypeName ((*SubObjectList)->Common.Type)));
448                return_ACPI_STATUS (AE_BAD_DATA);
449            }
450
451            /*
452             * Point to the next ACPI_OPERAND_OBJECT
453             */
454            TopObjectList++;
455        }
456
457        DEBUG_PRINTP (VERBOSE_INFO, ("OutputBuffer = %p\n", OutputBuffer));
458    }
459
460    else
461    {
462        *OutputBufferLength = BufferSizeNeeded;
463
464        return_ACPI_STATUS (AE_BUFFER_OVERFLOW);
465    }
466
467    /*
468     * Report the amount of buffer used
469     */
470    *OutputBufferLength = BufferSizeNeeded;
471    return_ACPI_STATUS (AE_OK);
472}
473
474
475/*******************************************************************************
476 *
477 * FUNCTION:    AcpiRsCreateByteStream
478 *
479 * PARAMETERS:  LinkedListBuffer        - Pointer to the resource linked list
480 *              OutputBuffer            - Pointer to the user's buffer
481 *              OutputBufferLength      - Size of OutputBuffer
482 *
483 * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code.
484 *              If the OutputBuffer is too small, the error will be
485 *              AE_BUFFER_OVERFLOW and OutputBufferLength will point
486 *              to the size buffer needed.
487 *
488 * DESCRIPTION: Takes the linked list of device resources and
489 *              creates a bytestream to be used as input for the
490 *              _SRS control method.
491 *
492 ******************************************************************************/
493
494ACPI_STATUS
495AcpiRsCreateByteStream (
496    ACPI_RESOURCE           *LinkedListBuffer,
497    UINT8                   *OutputBuffer,
498    UINT32                  *OutputBufferLength)
499{
500    ACPI_STATUS             Status;
501    UINT32                  ByteStreamSizeNeeded = 0;
502
503
504    FUNCTION_TRACE ("RsCreateByteStream");
505
506
507    DEBUG_PRINTP (VERBOSE_INFO, ("LinkedListBuffer = %p\n", LinkedListBuffer));
508
509    /*
510     * Params already validated, so we don't re-validate here
511     *
512     * Pass the LinkedListBuffer into a module that can calculate
513     * the buffer size needed for the byte stream.
514     */
515    Status = AcpiRsCalculateByteStreamLength (LinkedListBuffer,
516                &ByteStreamSizeNeeded);
517
518    DEBUG_PRINTP (VERBOSE_INFO, ("ByteStreamSizeNeeded=%X, %s\n",
519        ByteStreamSizeNeeded, AcpiUtFormatException (Status)));
520
521    /*
522     * Exit with the error passed back
523     */
524    if (ACPI_FAILURE (Status))
525    {
526        return_ACPI_STATUS (Status);
527    }
528
529    /*
530     * If the linked list will fit into the available buffer
531     * call to fill in the list
532     */
533
534    if (ByteStreamSizeNeeded <= *OutputBufferLength)
535    {
536        /*
537         * Zero out the return buffer before proceeding
538         */
539        MEMSET (OutputBuffer, 0x00, *OutputBufferLength);
540
541        Status = AcpiRsListToByteStream (LinkedListBuffer, ByteStreamSizeNeeded,
542                    &OutputBuffer);
543
544        /*
545         * Exit with the error passed back
546         */
547        if (ACPI_FAILURE (Status))
548        {
549            return_ACPI_STATUS (Status);
550        }
551
552        DEBUG_PRINTP (VERBOSE_INFO, ("OutputBuffer = %p\n", OutputBuffer));
553    }
554
555    else
556    {
557        *OutputBufferLength = ByteStreamSizeNeeded;
558        return_ACPI_STATUS (AE_BUFFER_OVERFLOW);
559    }
560
561    return_ACPI_STATUS (AE_OK);
562}
563
564