kernel: scheduling fix for ARM
[minix.git] / drivers / acpi / resources / rscreate.c
blob5f78b9e5ee2c42aab493fa94e6fd46e8a712cea1
1 /*******************************************************************************
3 * Module Name: rscreate - Create resource lists/tables
5 ******************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
14 * 2. License
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
19 * property rights.
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
38 * conditions are met:
40 * 3. Conditions
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
64 * make.
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
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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
88 * PARTICULAR PURPOSE.
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
97 * LIMITED REMEDY.
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 #define __RSCREATE_C__
118 #include "acpi.h"
119 #include "accommon.h"
120 #include "acresrc.h"
121 #include "acnamesp.h"
123 #define _COMPONENT ACPI_RESOURCES
124 ACPI_MODULE_NAME ("rscreate")
127 /*******************************************************************************
129 * FUNCTION: AcpiRsCreateResourceList
131 * PARAMETERS: AmlBuffer - Pointer to the resource byte stream
132 * OutputBuffer - Pointer to the user's buffer
134 * RETURN: Status: AE_OK if okay, else a valid ACPI_STATUS code
135 * If OutputBuffer is not large enough, OutputBufferLength
136 * indicates how large OutputBuffer should be, else it
137 * indicates how may UINT8 elements of OutputBuffer are valid.
139 * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method
140 * execution and parses the stream to create a linked list
141 * of device resources.
143 ******************************************************************************/
145 ACPI_STATUS
146 AcpiRsCreateResourceList (
147 ACPI_OPERAND_OBJECT *AmlBuffer,
148 ACPI_BUFFER *OutputBuffer)
151 ACPI_STATUS Status;
152 UINT8 *AmlStart;
153 ACPI_SIZE ListSizeNeeded = 0;
154 UINT32 AmlBufferLength;
155 void *Resource;
158 ACPI_FUNCTION_TRACE (RsCreateResourceList);
161 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlBuffer = %p\n",
162 AmlBuffer));
164 /* Params already validated, so we don't re-validate here */
166 AmlBufferLength = AmlBuffer->Buffer.Length;
167 AmlStart = AmlBuffer->Buffer.Pointer;
170 * Pass the AmlBuffer into a module that can calculate
171 * the buffer size needed for the linked list
173 Status = AcpiRsGetListLength (AmlStart, AmlBufferLength,
174 &ListSizeNeeded);
176 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n",
177 Status, (UINT32) ListSizeNeeded));
178 if (ACPI_FAILURE (Status))
180 return_ACPI_STATUS (Status);
183 /* Validate/Allocate/Clear caller buffer */
185 Status = AcpiUtInitializeBuffer (OutputBuffer, ListSizeNeeded);
186 if (ACPI_FAILURE (Status))
188 return_ACPI_STATUS (Status);
191 /* Do the conversion */
193 Resource = OutputBuffer->Pointer;
194 Status = AcpiUtWalkAmlResources (AmlStart, AmlBufferLength,
195 AcpiRsConvertAmlToResources, &Resource);
196 if (ACPI_FAILURE (Status))
198 return_ACPI_STATUS (Status);
201 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
202 OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
203 return_ACPI_STATUS (AE_OK);
207 /*******************************************************************************
209 * FUNCTION: AcpiRsCreatePciRoutingTable
211 * PARAMETERS: PackageObject - Pointer to an ACPI_OPERAND_OBJECT
212 * package
213 * OutputBuffer - Pointer to the user's buffer
215 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code.
216 * If the OutputBuffer is too small, the error will be
217 * AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
218 * to the size buffer needed.
220 * DESCRIPTION: Takes the ACPI_OPERAND_OBJECT package and creates a
221 * linked list of PCI interrupt descriptions
223 * NOTE: It is the caller's responsibility to ensure that the start of the
224 * output buffer is aligned properly (if necessary).
226 ******************************************************************************/
228 ACPI_STATUS
229 AcpiRsCreatePciRoutingTable (
230 ACPI_OPERAND_OBJECT *PackageObject,
231 ACPI_BUFFER *OutputBuffer)
233 UINT8 *Buffer;
234 ACPI_OPERAND_OBJECT **TopObjectList;
235 ACPI_OPERAND_OBJECT **SubObjectList;
236 ACPI_OPERAND_OBJECT *ObjDesc;
237 ACPI_SIZE BufferSizeNeeded = 0;
238 UINT32 NumberOfElements;
239 UINT32 Index;
240 ACPI_PCI_ROUTING_TABLE *UserPrt;
241 ACPI_NAMESPACE_NODE *Node;
242 ACPI_STATUS Status;
243 ACPI_BUFFER PathBuffer;
246 ACPI_FUNCTION_TRACE (RsCreatePciRoutingTable);
249 /* Params already validated, so we don't re-validate here */
251 /* Get the required buffer length */
253 Status = AcpiRsGetPciRoutingTableLength (PackageObject,
254 &BufferSizeNeeded);
255 if (ACPI_FAILURE (Status))
257 return_ACPI_STATUS (Status);
260 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "BufferSizeNeeded = %X\n",
261 (UINT32) BufferSizeNeeded));
263 /* Validate/Allocate/Clear caller buffer */
265 Status = AcpiUtInitializeBuffer (OutputBuffer, BufferSizeNeeded);
266 if (ACPI_FAILURE (Status))
268 return_ACPI_STATUS (Status);
272 * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a
273 * package that in turn contains an UINT64 Address, a UINT8 Pin,
274 * a Name, and a UINT8 SourceIndex.
276 TopObjectList = PackageObject->Package.Elements;
277 NumberOfElements = PackageObject->Package.Count;
278 Buffer = OutputBuffer->Pointer;
279 UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer);
281 for (Index = 0; Index < NumberOfElements; Index++)
284 * Point UserPrt past this current structure
286 * NOTE: On the first iteration, UserPrt->Length will
287 * be zero because we cleared the return buffer earlier
289 Buffer += UserPrt->Length;
290 UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer);
293 * Fill in the Length field with the information we have at this point.
294 * The minus four is to subtract the size of the UINT8 Source[4] member
295 * because it is added below.
297 UserPrt->Length = (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
299 /* Each element of the top-level package must also be a package */
301 if ((*TopObjectList)->Common.Type != ACPI_TYPE_PACKAGE)
303 ACPI_ERROR ((AE_INFO,
304 "(PRT[%u]) Need sub-package, found %s",
305 Index, AcpiUtGetObjectTypeName (*TopObjectList)));
306 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
309 /* Each sub-package must be of length 4 */
311 if ((*TopObjectList)->Package.Count != 4)
313 ACPI_ERROR ((AE_INFO,
314 "(PRT[%u]) Need package of length 4, found length %u",
315 Index, (*TopObjectList)->Package.Count));
316 return_ACPI_STATUS (AE_AML_PACKAGE_LIMIT);
320 * Dereference the sub-package.
321 * The SubObjectList will now point to an array of the four IRQ
322 * elements: [Address, Pin, Source, SourceIndex]
324 SubObjectList = (*TopObjectList)->Package.Elements;
326 /* 1) First subobject: Dereference the PRT.Address */
328 ObjDesc = SubObjectList[0];
329 if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
331 ACPI_ERROR ((AE_INFO, "(PRT[%u].Address) Need Integer, found %s",
332 Index, AcpiUtGetObjectTypeName (ObjDesc)));
333 return_ACPI_STATUS (AE_BAD_DATA);
336 UserPrt->Address = ObjDesc->Integer.Value;
338 /* 2) Second subobject: Dereference the PRT.Pin */
340 ObjDesc = SubObjectList[1];
341 if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
343 ACPI_ERROR ((AE_INFO, "(PRT[%u].Pin) Need Integer, found %s",
344 Index, AcpiUtGetObjectTypeName (ObjDesc)));
345 return_ACPI_STATUS (AE_BAD_DATA);
348 UserPrt->Pin = (UINT32) ObjDesc->Integer.Value;
351 * If the BIOS has erroneously reversed the _PRT SourceName (index 2)
352 * and the SourceIndex (index 3), fix it. _PRT is important enough to
353 * workaround this BIOS error. This also provides compatibility with
354 * other ACPI implementations.
356 ObjDesc = SubObjectList[3];
357 if (!ObjDesc || (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
359 SubObjectList[3] = SubObjectList[2];
360 SubObjectList[2] = ObjDesc;
362 ACPI_WARNING ((AE_INFO,
363 "(PRT[%X].Source) SourceName and SourceIndex are reversed, fixed",
364 Index));
368 * 3) Third subobject: Dereference the PRT.SourceName
369 * The name may be unresolved (slack mode), so allow a null object
371 ObjDesc = SubObjectList[2];
372 if (ObjDesc)
374 switch (ObjDesc->Common.Type)
376 case ACPI_TYPE_LOCAL_REFERENCE:
378 if (ObjDesc->Reference.Class != ACPI_REFCLASS_NAME)
380 ACPI_ERROR ((AE_INFO,
381 "(PRT[%u].Source) Need name, found Reference Class 0x%X",
382 Index, ObjDesc->Reference.Class));
383 return_ACPI_STATUS (AE_BAD_DATA);
386 Node = ObjDesc->Reference.Node;
388 /* Use *remaining* length of the buffer as max for pathname */
390 PathBuffer.Length = OutputBuffer->Length -
391 (UINT32) ((UINT8 *) UserPrt->Source -
392 (UINT8 *) OutputBuffer->Pointer);
393 PathBuffer.Pointer = UserPrt->Source;
395 Status = AcpiNsHandleToPathname ((ACPI_HANDLE) Node, &PathBuffer);
397 /* +1 to include null terminator */
399 UserPrt->Length += (UINT32) ACPI_STRLEN (UserPrt->Source) + 1;
400 break;
403 case ACPI_TYPE_STRING:
405 ACPI_STRCPY (UserPrt->Source, ObjDesc->String.Pointer);
408 * Add to the Length field the length of the string
409 * (add 1 for terminator)
411 UserPrt->Length += ObjDesc->String.Length + 1;
412 break;
415 case ACPI_TYPE_INTEGER:
417 * If this is a number, then the Source Name is NULL, since the
418 * entire buffer was zeroed out, we can leave this alone.
420 * Add to the Length field the length of the UINT32 NULL
422 UserPrt->Length += sizeof (UINT32);
423 break;
426 default:
428 ACPI_ERROR ((AE_INFO,
429 "(PRT[%u].Source) Need Ref/String/Integer, found %s",
430 Index, AcpiUtGetObjectTypeName (ObjDesc)));
431 return_ACPI_STATUS (AE_BAD_DATA);
435 /* Now align the current length */
437 UserPrt->Length = (UINT32) ACPI_ROUND_UP_TO_64BIT (UserPrt->Length);
439 /* 4) Fourth subobject: Dereference the PRT.SourceIndex */
441 ObjDesc = SubObjectList[3];
442 if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
444 ACPI_ERROR ((AE_INFO,
445 "(PRT[%u].SourceIndex) Need Integer, found %s",
446 Index, AcpiUtGetObjectTypeName (ObjDesc)));
447 return_ACPI_STATUS (AE_BAD_DATA);
450 UserPrt->SourceIndex = (UINT32) ObjDesc->Integer.Value;
452 /* Point to the next ACPI_OPERAND_OBJECT in the top level package */
454 TopObjectList++;
457 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
458 OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
459 return_ACPI_STATUS (AE_OK);
463 /*******************************************************************************
465 * FUNCTION: AcpiRsCreateAmlResources
467 * PARAMETERS: LinkedListBuffer - Pointer to the resource linked list
468 * OutputBuffer - Pointer to the user's buffer
470 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code.
471 * If the OutputBuffer is too small, the error will be
472 * AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
473 * to the size buffer needed.
475 * DESCRIPTION: Takes the linked list of device resources and
476 * creates a bytestream to be used as input for the
477 * _SRS control method.
479 ******************************************************************************/
481 ACPI_STATUS
482 AcpiRsCreateAmlResources (
483 ACPI_RESOURCE *LinkedListBuffer,
484 ACPI_BUFFER *OutputBuffer)
486 ACPI_STATUS Status;
487 ACPI_SIZE AmlSizeNeeded = 0;
490 ACPI_FUNCTION_TRACE (RsCreateAmlResources);
493 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "LinkedListBuffer = %p\n",
494 LinkedListBuffer));
497 * Params already validated, so we don't re-validate here
499 * Pass the LinkedListBuffer into a module that calculates
500 * the buffer size needed for the byte stream.
502 Status = AcpiRsGetAmlLength (LinkedListBuffer,
503 &AmlSizeNeeded);
505 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n",
506 (UINT32) AmlSizeNeeded, AcpiFormatException (Status)));
507 if (ACPI_FAILURE (Status))
509 return_ACPI_STATUS (Status);
512 /* Validate/Allocate/Clear caller buffer */
514 Status = AcpiUtInitializeBuffer (OutputBuffer, AmlSizeNeeded);
515 if (ACPI_FAILURE (Status))
517 return_ACPI_STATUS (Status);
520 /* Do the conversion */
522 Status = AcpiRsConvertResourcesToAml (LinkedListBuffer, AmlSizeNeeded,
523 OutputBuffer->Pointer);
524 if (ACPI_FAILURE (Status))
526 return_ACPI_STATUS (Status);
529 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
530 OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
531 return_ACPI_STATUS (AE_OK);