1 /*******************************************************************************
3 * Module Name: rscreate - Create resource lists/tables
5 ******************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2019, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
153 #include "accommon.h"
155 #include "acnamesp.h"
157 #define _COMPONENT ACPI_RESOURCES
158 ACPI_MODULE_NAME ("rscreate")
161 /*******************************************************************************
163 * FUNCTION: AcpiBufferToResource
165 * PARAMETERS: AmlBuffer - Pointer to the resource byte stream
166 * AmlBufferLength - Length of the AmlBuffer
167 * ResourcePtr - Where the converted resource is returned
171 * DESCRIPTION: Convert a raw AML buffer to a resource list
173 ******************************************************************************/
176 AcpiBufferToResource (
178 UINT16 AmlBufferLength,
179 ACPI_RESOURCE **ResourcePtr)
182 ACPI_SIZE ListSizeNeeded;
184 void *CurrentResourcePtr;
187 ACPI_FUNCTION_TRACE (AcpiBufferToResource);
191 * Note: we allow AE_AML_NO_RESOURCE_END_TAG, since an end tag
192 * is not required here.
195 /* Get the required length for the converted resource */
197 Status = AcpiRsGetListLength (
198 AmlBuffer, AmlBufferLength, &ListSizeNeeded);
199 if (Status == AE_AML_NO_RESOURCE_END_TAG)
203 if (ACPI_FAILURE (Status))
205 return_ACPI_STATUS (Status);
208 /* Allocate a buffer for the converted resource */
210 Resource = ACPI_ALLOCATE_ZEROED (ListSizeNeeded);
211 CurrentResourcePtr = Resource;
214 return_ACPI_STATUS (AE_NO_MEMORY);
217 /* Perform the AML-to-Resource conversion */
219 Status = AcpiUtWalkAmlResources (NULL, AmlBuffer, AmlBufferLength,
220 AcpiRsConvertAmlToResources, &CurrentResourcePtr);
221 if (Status == AE_AML_NO_RESOURCE_END_TAG)
225 if (ACPI_FAILURE (Status))
227 ACPI_FREE (Resource);
231 *ResourcePtr = Resource;
234 return_ACPI_STATUS (Status);
237 ACPI_EXPORT_SYMBOL (AcpiBufferToResource)
240 /*******************************************************************************
242 * FUNCTION: AcpiRsCreateResourceList
244 * PARAMETERS: AmlBuffer - Pointer to the resource byte stream
245 * OutputBuffer - Pointer to the user's buffer
247 * RETURN: Status: AE_OK if okay, else a valid ACPI_STATUS code
248 * If OutputBuffer is not large enough, OutputBufferLength
249 * indicates how large OutputBuffer should be, else it
250 * indicates how may UINT8 elements of OutputBuffer are valid.
252 * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method
253 * execution and parses the stream to create a linked list
254 * of device resources.
256 ******************************************************************************/
259 AcpiRsCreateResourceList (
260 ACPI_OPERAND_OBJECT *AmlBuffer,
261 ACPI_BUFFER *OutputBuffer)
266 ACPI_SIZE ListSizeNeeded = 0;
267 UINT32 AmlBufferLength;
271 ACPI_FUNCTION_TRACE (RsCreateResourceList);
274 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlBuffer = %p\n",
277 /* Params already validated, so we don't re-validate here */
279 AmlBufferLength = AmlBuffer->Buffer.Length;
280 AmlStart = AmlBuffer->Buffer.Pointer;
283 * Pass the AmlBuffer into a module that can calculate
284 * the buffer size needed for the linked list
286 Status = AcpiRsGetListLength (AmlStart, AmlBufferLength,
289 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n",
290 Status, (UINT32) ListSizeNeeded));
291 if (ACPI_FAILURE (Status))
293 return_ACPI_STATUS (Status);
296 /* Validate/Allocate/Clear caller buffer */
298 Status = AcpiUtInitializeBuffer (OutputBuffer, ListSizeNeeded);
299 if (ACPI_FAILURE (Status))
301 return_ACPI_STATUS (Status);
304 /* Do the conversion */
306 Resource = OutputBuffer->Pointer;
307 Status = AcpiUtWalkAmlResources (NULL, AmlStart, AmlBufferLength,
308 AcpiRsConvertAmlToResources, &Resource);
309 if (ACPI_FAILURE (Status))
311 return_ACPI_STATUS (Status);
314 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
315 OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
316 return_ACPI_STATUS (AE_OK);
320 /*******************************************************************************
322 * FUNCTION: AcpiRsCreatePciRoutingTable
324 * PARAMETERS: PackageObject - Pointer to a package containing one
325 * of more ACPI_OPERAND_OBJECTs
326 * OutputBuffer - Pointer to the user's buffer
328 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code.
329 * If the OutputBuffer is too small, the error will be
330 * AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
331 * to the size buffer needed.
333 * DESCRIPTION: Takes the ACPI_OPERAND_OBJECT package and creates a
334 * linked list of PCI interrupt descriptions
336 * NOTE: It is the caller's responsibility to ensure that the start of the
337 * output buffer is aligned properly (if necessary).
339 ******************************************************************************/
342 AcpiRsCreatePciRoutingTable (
343 ACPI_OPERAND_OBJECT *PackageObject,
344 ACPI_BUFFER *OutputBuffer)
347 ACPI_OPERAND_OBJECT **TopObjectList;
348 ACPI_OPERAND_OBJECT **SubObjectList;
349 ACPI_OPERAND_OBJECT *ObjDesc;
350 ACPI_SIZE BufferSizeNeeded = 0;
351 UINT32 NumberOfElements;
353 ACPI_PCI_ROUTING_TABLE *UserPrt;
354 ACPI_NAMESPACE_NODE *Node;
356 ACPI_BUFFER PathBuffer;
359 ACPI_FUNCTION_TRACE (RsCreatePciRoutingTable);
362 /* Params already validated, so we don't re-validate here */
364 /* Get the required buffer length */
366 Status = AcpiRsGetPciRoutingTableLength (
367 PackageObject,&BufferSizeNeeded);
368 if (ACPI_FAILURE (Status))
370 return_ACPI_STATUS (Status);
373 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "BufferSizeNeeded = %X\n",
374 (UINT32) BufferSizeNeeded));
376 /* Validate/Allocate/Clear caller buffer */
378 Status = AcpiUtInitializeBuffer (OutputBuffer, BufferSizeNeeded);
379 if (ACPI_FAILURE (Status))
381 return_ACPI_STATUS (Status);
385 * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a
386 * package that in turn contains an UINT64 Address, a UINT8 Pin,
387 * a Name, and a UINT8 SourceIndex.
389 TopObjectList = PackageObject->Package.Elements;
390 NumberOfElements = PackageObject->Package.Count;
391 Buffer = OutputBuffer->Pointer;
392 UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer);
394 for (Index = 0; Index < NumberOfElements; Index++)
397 * Point UserPrt past this current structure
399 * NOTE: On the first iteration, UserPrt->Length will
400 * be zero because we cleared the return buffer earlier
402 Buffer += UserPrt->Length;
403 UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer);
406 * Fill in the Length field with the information we have at this
407 * point. The minus four is to subtract the size of the UINT8
408 * Source[4] member because it is added below.
410 UserPrt->Length = (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
412 /* Each subpackage must be of length 4 */
414 if ((*TopObjectList)->Package.Count != 4)
416 ACPI_ERROR ((AE_INFO,
417 "(PRT[%u]) Need package of length 4, found length %u",
418 Index, (*TopObjectList)->Package.Count));
419 return_ACPI_STATUS (AE_AML_PACKAGE_LIMIT);
423 * Dereference the subpackage.
424 * The SubObjectList will now point to an array of the four IRQ
425 * elements: [Address, Pin, Source, SourceIndex]
427 SubObjectList = (*TopObjectList)->Package.Elements;
429 /* 1) First subobject: Dereference the PRT.Address */
431 ObjDesc = SubObjectList[0];
432 if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
434 ACPI_ERROR ((AE_INFO,
435 "(PRT[%u].Address) Need Integer, found %s",
436 Index, AcpiUtGetObjectTypeName (ObjDesc)));
437 return_ACPI_STATUS (AE_BAD_DATA);
440 UserPrt->Address = ObjDesc->Integer.Value;
442 /* 2) Second subobject: Dereference the PRT.Pin */
444 ObjDesc = SubObjectList[1];
445 if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
447 ACPI_ERROR ((AE_INFO, "(PRT[%u].Pin) Need Integer, found %s",
448 Index, AcpiUtGetObjectTypeName (ObjDesc)));
449 return_ACPI_STATUS (AE_BAD_DATA);
452 UserPrt->Pin = (UINT32) ObjDesc->Integer.Value;
455 * 3) Third subobject: Dereference the PRT.SourceName
456 * The name may be unresolved (slack mode), so allow a null object
458 ObjDesc = SubObjectList[2];
461 switch (ObjDesc->Common.Type)
463 case ACPI_TYPE_LOCAL_REFERENCE:
465 if (ObjDesc->Reference.Class != ACPI_REFCLASS_NAME)
467 ACPI_ERROR ((AE_INFO,
468 "(PRT[%u].Source) Need name, found Reference Class 0x%X",
469 Index, ObjDesc->Reference.Class));
470 return_ACPI_STATUS (AE_BAD_DATA);
473 Node = ObjDesc->Reference.Node;
475 /* Use *remaining* length of the buffer as max for pathname */
477 PathBuffer.Length = OutputBuffer->Length -
478 (UINT32) ((UINT8 *) UserPrt->Source -
479 (UINT8 *) OutputBuffer->Pointer);
480 PathBuffer.Pointer = UserPrt->Source;
482 Status = AcpiNsHandleToPathname (
483 (ACPI_HANDLE) Node, &PathBuffer, FALSE);
485 /* +1 to include null terminator */
487 UserPrt->Length += (UINT32) strlen (UserPrt->Source) + 1;
490 case ACPI_TYPE_STRING:
492 strcpy (UserPrt->Source, ObjDesc->String.Pointer);
495 * Add to the Length field the length of the string
496 * (add 1 for terminator)
498 UserPrt->Length += ObjDesc->String.Length + 1;
501 case ACPI_TYPE_INTEGER:
503 * If this is a number, then the Source Name is NULL, since
504 * the entire buffer was zeroed out, we can leave this alone.
506 * Add to the Length field the length of the UINT32 NULL
508 UserPrt->Length += sizeof (UINT32);
513 ACPI_ERROR ((AE_INFO,
514 "(PRT[%u].Source) Need Ref/String/Integer, found %s",
515 Index, AcpiUtGetObjectTypeName (ObjDesc)));
516 return_ACPI_STATUS (AE_BAD_DATA);
520 /* Now align the current length */
522 UserPrt->Length = (UINT32) ACPI_ROUND_UP_TO_64BIT (UserPrt->Length);
524 /* 4) Fourth subobject: Dereference the PRT.SourceIndex */
526 ObjDesc = SubObjectList[3];
527 if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
529 ACPI_ERROR ((AE_INFO,
530 "(PRT[%u].SourceIndex) Need Integer, found %s",
531 Index, AcpiUtGetObjectTypeName (ObjDesc)));
532 return_ACPI_STATUS (AE_BAD_DATA);
535 UserPrt->SourceIndex = (UINT32) ObjDesc->Integer.Value;
537 /* Point to the next ACPI_OPERAND_OBJECT in the top level package */
542 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
543 OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
544 return_ACPI_STATUS (AE_OK);
548 /*******************************************************************************
550 * FUNCTION: AcpiRsCreateAmlResources
552 * PARAMETERS: ResourceList - Pointer to the resource list buffer
553 * OutputBuffer - Where the AML buffer is returned
555 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code.
556 * If the OutputBuffer is too small, the error will be
557 * AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
558 * to the size buffer needed.
560 * DESCRIPTION: Converts a list of device resources to an AML bytestream
561 * to be used as input for the _SRS control method.
563 ******************************************************************************/
566 AcpiRsCreateAmlResources (
567 ACPI_BUFFER *ResourceList,
568 ACPI_BUFFER *OutputBuffer)
571 ACPI_SIZE AmlSizeNeeded = 0;
574 ACPI_FUNCTION_TRACE (RsCreateAmlResources);
577 /* Params already validated, no need to re-validate here */
579 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ResourceList Buffer = %p\n",
580 ResourceList->Pointer));
582 /* Get the buffer size needed for the AML byte stream */
584 Status = AcpiRsGetAmlLength (
585 ResourceList->Pointer, ResourceList->Length, &AmlSizeNeeded);
587 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n",
588 (UINT32) AmlSizeNeeded, AcpiFormatException (Status)));
589 if (ACPI_FAILURE (Status))
591 return_ACPI_STATUS (Status);
594 /* Validate/Allocate/Clear caller buffer */
596 Status = AcpiUtInitializeBuffer (OutputBuffer, AmlSizeNeeded);
597 if (ACPI_FAILURE (Status))
599 return_ACPI_STATUS (Status);
602 /* Do the conversion */
604 Status = AcpiRsConvertResourcesToAml (ResourceList->Pointer,
605 AmlSizeNeeded, OutputBuffer->Pointer);
606 if (ACPI_FAILURE (Status))
608 return_ACPI_STATUS (Status);
611 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
612 OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
613 return_ACPI_STATUS (AE_OK);