1 /*******************************************************************************
3 * Module Name: rscreate - Create resource lists/tables
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
13 * All rights reserved.
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
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
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;
38 * The above copyright and patent license is granted only if the following
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.
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
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
73 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
81 * 4. Disclaimer and Export Compliance
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
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
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.
115 *****************************************************************************/
118 #define __RSCREATE_C__
123 #include "acnamesp.h"
125 #define _COMPONENT ACPI_RESOURCES
126 ACPI_MODULE_NAME ("rscreate")
129 /*******************************************************************************
131 * FUNCTION: AcpiRsCreateResourceList
133 * PARAMETERS: AmlBuffer - Pointer to the resource byte stream
134 * OutputBuffer - Pointer to the user's buffer
136 * RETURN: Status: AE_OK if okay, else a valid ACPI_STATUS code
137 * If OutputBuffer is not large enough, OutputBufferLength
138 * indicates how large OutputBuffer should be, else it
139 * indicates how may UINT8 elements of OutputBuffer are valid.
141 * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method
142 * execution and parses the stream to create a linked list
143 * of device resources.
145 ******************************************************************************/
148 AcpiRsCreateResourceList (
149 ACPI_OPERAND_OBJECT
*AmlBuffer
,
150 ACPI_BUFFER
*OutputBuffer
)
155 ACPI_SIZE ListSizeNeeded
= 0;
156 UINT32 AmlBufferLength
;
160 ACPI_FUNCTION_TRACE (RsCreateResourceList
);
163 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "AmlBuffer = %p\n",
166 /* Params already validated, so we don't re-validate here */
168 AmlBufferLength
= AmlBuffer
->Buffer
.Length
;
169 AmlStart
= AmlBuffer
->Buffer
.Pointer
;
172 * Pass the AmlBuffer into a module that can calculate
173 * the buffer size needed for the linked list
175 Status
= AcpiRsGetListLength (AmlStart
, AmlBufferLength
,
178 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "Status=%X ListSizeNeeded=%X\n",
179 Status
, (UINT32
) ListSizeNeeded
));
180 if (ACPI_FAILURE (Status
))
182 return_ACPI_STATUS (Status
);
185 /* Validate/Allocate/Clear caller buffer */
187 Status
= AcpiUtInitializeBuffer (OutputBuffer
, ListSizeNeeded
);
188 if (ACPI_FAILURE (Status
))
190 return_ACPI_STATUS (Status
);
193 /* Do the conversion */
195 Resource
= OutputBuffer
->Pointer
;
196 Status
= AcpiUtWalkAmlResources (AmlStart
, AmlBufferLength
,
197 AcpiRsConvertAmlToResources
, &Resource
);
198 if (ACPI_FAILURE (Status
))
200 return_ACPI_STATUS (Status
);
203 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "OutputBuffer %p Length %X\n",
204 OutputBuffer
->Pointer
, (UINT32
) OutputBuffer
->Length
));
205 return_ACPI_STATUS (AE_OK
);
209 /*******************************************************************************
211 * FUNCTION: AcpiRsCreatePciRoutingTable
213 * PARAMETERS: PackageObject - Pointer to an ACPI_OPERAND_OBJECT
215 * OutputBuffer - Pointer to the user's buffer
217 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code.
218 * If the OutputBuffer is too small, the error will be
219 * AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
220 * to the size buffer needed.
222 * DESCRIPTION: Takes the ACPI_OPERAND_OBJECT package and creates a
223 * linked list of PCI interrupt descriptions
225 * NOTE: It is the caller's responsibility to ensure that the start of the
226 * output buffer is aligned properly (if necessary).
228 ******************************************************************************/
231 AcpiRsCreatePciRoutingTable (
232 ACPI_OPERAND_OBJECT
*PackageObject
,
233 ACPI_BUFFER
*OutputBuffer
)
236 ACPI_OPERAND_OBJECT
**TopObjectList
;
237 ACPI_OPERAND_OBJECT
**SubObjectList
;
238 ACPI_OPERAND_OBJECT
*ObjDesc
;
239 ACPI_SIZE BufferSizeNeeded
= 0;
240 UINT32 NumberOfElements
;
242 ACPI_PCI_ROUTING_TABLE
*UserPrt
;
243 ACPI_NAMESPACE_NODE
*Node
;
245 ACPI_BUFFER PathBuffer
;
248 ACPI_FUNCTION_TRACE (RsCreatePciRoutingTable
);
251 /* Params already validated, so we don't re-validate here */
253 /* Get the required buffer length */
255 Status
= AcpiRsGetPciRoutingTableLength (PackageObject
,
257 if (ACPI_FAILURE (Status
))
259 return_ACPI_STATUS (Status
);
262 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "BufferSizeNeeded = %X\n",
263 (UINT32
) BufferSizeNeeded
));
265 /* Validate/Allocate/Clear caller buffer */
267 Status
= AcpiUtInitializeBuffer (OutputBuffer
, BufferSizeNeeded
);
268 if (ACPI_FAILURE (Status
))
270 return_ACPI_STATUS (Status
);
274 * Loop through the ACPI_INTERNAL_OBJECTS - Each object
275 * should be a package that in turn contains an
276 * ACPI_INTEGER Address, a UINT8 Pin, a Name and a UINT8 SourceIndex.
278 TopObjectList
= PackageObject
->Package
.Elements
;
279 NumberOfElements
= PackageObject
->Package
.Count
;
280 Buffer
= OutputBuffer
->Pointer
;
281 UserPrt
= ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE
, Buffer
);
283 for (Index
= 0; Index
< NumberOfElements
; Index
++)
286 * Point UserPrt past this current structure
288 * NOTE: On the first iteration, UserPrt->Length will
289 * be zero because we cleared the return buffer earlier
291 Buffer
+= UserPrt
->Length
;
292 UserPrt
= ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE
, Buffer
);
295 * Fill in the Length field with the information we have at this point.
296 * The minus four is to subtract the size of the UINT8 Source[4] member
297 * because it is added below.
299 UserPrt
->Length
= (sizeof (ACPI_PCI_ROUTING_TABLE
) - 4);
301 /* Each element of the top-level package must also be a package */
303 if (ACPI_GET_OBJECT_TYPE (*TopObjectList
) != ACPI_TYPE_PACKAGE
)
305 ACPI_ERROR ((AE_INFO
,
306 "(PRT[%X]) Need sub-package, found %s",
307 Index
, AcpiUtGetObjectTypeName (*TopObjectList
)));
308 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
311 /* Each sub-package must be of length 4 */
313 if ((*TopObjectList
)->Package
.Count
!= 4)
315 ACPI_ERROR ((AE_INFO
,
316 "(PRT[%X]) Need package of length 4, found length %d",
317 Index
, (*TopObjectList
)->Package
.Count
));
318 return_ACPI_STATUS (AE_AML_PACKAGE_LIMIT
);
322 * Dereference the sub-package.
323 * The SubObjectList will now point to an array of the four IRQ
324 * elements: [Address, Pin, Source, SourceIndex]
326 SubObjectList
= (*TopObjectList
)->Package
.Elements
;
328 /* 1) First subobject: Dereference the PRT.Address */
330 ObjDesc
= SubObjectList
[0];
331 if (ACPI_GET_OBJECT_TYPE (ObjDesc
) == ACPI_TYPE_INTEGER
)
333 UserPrt
->Address
= ObjDesc
->Integer
.Value
;
337 ACPI_ERROR ((AE_INFO
,
338 "(PRT[%X].Address) Need Integer, found %s",
339 Index
, AcpiUtGetObjectTypeName (ObjDesc
)));
340 return_ACPI_STATUS (AE_BAD_DATA
);
343 /* 2) Second subobject: Dereference the PRT.Pin */
345 ObjDesc
= SubObjectList
[1];
346 if (ACPI_GET_OBJECT_TYPE (ObjDesc
) == ACPI_TYPE_INTEGER
)
348 UserPrt
->Pin
= (UINT32
) ObjDesc
->Integer
.Value
;
352 ACPI_ERROR ((AE_INFO
,
353 "(PRT[%X].Pin) Need Integer, found %s",
354 Index
, AcpiUtGetObjectTypeName (ObjDesc
)));
355 return_ACPI_STATUS (AE_BAD_DATA
);
359 * 3) Third subobject: Dereference the PRT.SourceName
360 * The name may be unresolved (slack mode), so allow a null object
362 ObjDesc
= SubObjectList
[2];
365 switch (ACPI_GET_OBJECT_TYPE (ObjDesc
))
367 case ACPI_TYPE_LOCAL_REFERENCE
:
369 if (ObjDesc
->Reference
.Opcode
!= AML_INT_NAMEPATH_OP
)
371 ACPI_ERROR ((AE_INFO
,
372 "(PRT[%X].Source) Need name, found reference op %X",
373 Index
, ObjDesc
->Reference
.Opcode
));
374 return_ACPI_STATUS (AE_BAD_DATA
);
377 Node
= ObjDesc
->Reference
.Node
;
379 /* Use *remaining* length of the buffer as max for pathname */
381 PathBuffer
.Length
= OutputBuffer
->Length
-
382 (UINT32
) ((UINT8
*) UserPrt
->Source
-
383 (UINT8
*) OutputBuffer
->Pointer
);
384 PathBuffer
.Pointer
= UserPrt
->Source
;
386 Status
= AcpiNsHandleToPathname ((ACPI_HANDLE
) Node
, &PathBuffer
);
388 /* +1 to include null terminator */
390 UserPrt
->Length
+= (UINT32
) ACPI_STRLEN (UserPrt
->Source
) + 1;
394 case ACPI_TYPE_STRING
:
396 ACPI_STRCPY (UserPrt
->Source
, ObjDesc
->String
.Pointer
);
399 * Add to the Length field the length of the string
400 * (add 1 for terminator)
402 UserPrt
->Length
+= ObjDesc
->String
.Length
+ 1;
406 case ACPI_TYPE_INTEGER
:
408 * If this is a number, then the Source Name is NULL, since the
409 * entire buffer was zeroed out, we can leave this alone.
411 * Add to the Length field the length of the UINT32 NULL
413 UserPrt
->Length
+= sizeof (UINT32
);
419 ACPI_ERROR ((AE_INFO
,
420 "(PRT[%X].Source) Need Ref/String/Integer, found %s",
421 Index
, AcpiUtGetObjectTypeName (ObjDesc
)));
422 return_ACPI_STATUS (AE_BAD_DATA
);
426 /* Now align the current length */
428 UserPrt
->Length
= (UINT32
) ACPI_ROUND_UP_TO_64BIT (UserPrt
->Length
);
430 /* 4) Fourth subobject: Dereference the PRT.SourceIndex */
432 ObjDesc
= SubObjectList
[3];
433 if (ACPI_GET_OBJECT_TYPE (ObjDesc
) == ACPI_TYPE_INTEGER
)
435 UserPrt
->SourceIndex
= (UINT32
) ObjDesc
->Integer
.Value
;
439 ACPI_ERROR ((AE_INFO
,
440 "(PRT[%X].SourceIndex) Need Integer, found %s",
441 Index
, AcpiUtGetObjectTypeName (ObjDesc
)));
442 return_ACPI_STATUS (AE_BAD_DATA
);
445 /* Point to the next ACPI_OPERAND_OBJECT in the top level package */
450 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "OutputBuffer %p Length %X\n",
451 OutputBuffer
->Pointer
, (UINT32
) OutputBuffer
->Length
));
452 return_ACPI_STATUS (AE_OK
);
456 /*******************************************************************************
458 * FUNCTION: AcpiRsCreateAmlResources
460 * PARAMETERS: LinkedListBuffer - Pointer to the resource linked list
461 * OutputBuffer - Pointer to the user's buffer
463 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code.
464 * If the OutputBuffer is too small, the error will be
465 * AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
466 * to the size buffer needed.
468 * DESCRIPTION: Takes the linked list of device resources and
469 * creates a bytestream to be used as input for the
470 * _SRS control method.
472 ******************************************************************************/
475 AcpiRsCreateAmlResources (
476 ACPI_RESOURCE
*LinkedListBuffer
,
477 ACPI_BUFFER
*OutputBuffer
)
480 ACPI_SIZE AmlSizeNeeded
= 0;
483 ACPI_FUNCTION_TRACE (RsCreateAmlResources
);
486 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "LinkedListBuffer = %p\n",
490 * Params already validated, so we don't re-validate here
492 * Pass the LinkedListBuffer into a module that calculates
493 * the buffer size needed for the byte stream.
495 Status
= AcpiRsGetAmlLength (LinkedListBuffer
,
498 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "AmlSizeNeeded=%X, %s\n",
499 (UINT32
) AmlSizeNeeded
, AcpiFormatException (Status
)));
500 if (ACPI_FAILURE (Status
))
502 return_ACPI_STATUS (Status
);
505 /* Validate/Allocate/Clear caller buffer */
507 Status
= AcpiUtInitializeBuffer (OutputBuffer
, AmlSizeNeeded
);
508 if (ACPI_FAILURE (Status
))
510 return_ACPI_STATUS (Status
);
513 /* Do the conversion */
515 Status
= AcpiRsConvertResourcesToAml (LinkedListBuffer
, AmlSizeNeeded
,
516 OutputBuffer
->Pointer
);
517 if (ACPI_FAILURE (Status
))
519 return_ACPI_STATUS (Status
);
522 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "OutputBuffer %p Length %X\n",
523 OutputBuffer
->Pointer
, (UINT32
) OutputBuffer
->Length
));
524 return_ACPI_STATUS (AE_OK
);