VM: munmap used by VM for itself is no longer used
[minix.git] / drivers / acpi / utilities / utresrc.c
blob02bb1dbfe60adf8e63bdc2f8939f5bb1b6991266
1 /*******************************************************************************
3 * Module Name: utresrc - Resource managment utilities
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 *****************************************************************************/
117 #define __UTRESRC_C__
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "amlresrc.h"
124 #define _COMPONENT ACPI_UTILITIES
125 ACPI_MODULE_NAME ("utresrc")
128 #if defined(ACPI_DISASSEMBLER) || defined (ACPI_DEBUGGER)
131 * Strings used to decode resource descriptors.
132 * Used by both the disasssembler and the debugger resource dump routines
134 const char *AcpiGbl_BmDecode[] =
136 "NotBusMaster",
137 "BusMaster"
140 const char *AcpiGbl_ConfigDecode[] =
142 "0 - Good Configuration",
143 "1 - Acceptable Configuration",
144 "2 - Suboptimal Configuration",
145 "3 - ***Invalid Configuration***",
148 const char *AcpiGbl_ConsumeDecode[] =
150 "ResourceProducer",
151 "ResourceConsumer"
154 const char *AcpiGbl_DecDecode[] =
156 "PosDecode",
157 "SubDecode"
160 const char *AcpiGbl_HeDecode[] =
162 "Level",
163 "Edge"
166 const char *AcpiGbl_IoDecode[] =
168 "Decode10",
169 "Decode16"
172 const char *AcpiGbl_LlDecode[] =
174 "ActiveHigh",
175 "ActiveLow"
178 const char *AcpiGbl_MaxDecode[] =
180 "MaxNotFixed",
181 "MaxFixed"
184 const char *AcpiGbl_MemDecode[] =
186 "NonCacheable",
187 "Cacheable",
188 "WriteCombining",
189 "Prefetchable"
192 const char *AcpiGbl_MinDecode[] =
194 "MinNotFixed",
195 "MinFixed"
198 const char *AcpiGbl_MtpDecode[] =
200 "AddressRangeMemory",
201 "AddressRangeReserved",
202 "AddressRangeACPI",
203 "AddressRangeNVS"
206 const char *AcpiGbl_RngDecode[] =
208 "InvalidRanges",
209 "NonISAOnlyRanges",
210 "ISAOnlyRanges",
211 "EntireRange"
214 const char *AcpiGbl_RwDecode[] =
216 "ReadOnly",
217 "ReadWrite"
220 const char *AcpiGbl_ShrDecode[] =
222 "Exclusive",
223 "Shared"
226 const char *AcpiGbl_SizDecode[] =
228 "Transfer8",
229 "Transfer8_16",
230 "Transfer16",
231 "InvalidSize"
234 const char *AcpiGbl_TrsDecode[] =
236 "DenseTranslation",
237 "SparseTranslation"
240 const char *AcpiGbl_TtpDecode[] =
242 "TypeStatic",
243 "TypeTranslation"
246 const char *AcpiGbl_TypDecode[] =
248 "Compatibility",
249 "TypeA",
250 "TypeB",
251 "TypeF"
254 #endif
258 * Base sizes of the raw AML resource descriptors, indexed by resource type.
259 * Zero indicates a reserved (and therefore invalid) resource type.
261 const UINT8 AcpiGbl_ResourceAmlSizes[] =
263 /* Small descriptors */
269 ACPI_AML_SIZE_SMALL (AML_RESOURCE_IRQ),
270 ACPI_AML_SIZE_SMALL (AML_RESOURCE_DMA),
271 ACPI_AML_SIZE_SMALL (AML_RESOURCE_START_DEPENDENT),
272 ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_DEPENDENT),
273 ACPI_AML_SIZE_SMALL (AML_RESOURCE_IO),
274 ACPI_AML_SIZE_SMALL (AML_RESOURCE_FIXED_IO),
279 ACPI_AML_SIZE_SMALL (AML_RESOURCE_VENDOR_SMALL),
280 ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_TAG),
282 /* Large descriptors */
285 ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY24),
286 ACPI_AML_SIZE_LARGE (AML_RESOURCE_GENERIC_REGISTER),
288 ACPI_AML_SIZE_LARGE (AML_RESOURCE_VENDOR_LARGE),
289 ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY32),
290 ACPI_AML_SIZE_LARGE (AML_RESOURCE_FIXED_MEMORY32),
291 ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS32),
292 ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS16),
293 ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_IRQ),
294 ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS64),
295 ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_ADDRESS64)
300 * Resource types, used to validate the resource length field.
301 * The length of fixed-length types must match exactly, variable
302 * lengths must meet the minimum required length, etc.
303 * Zero indicates a reserved (and therefore invalid) resource type.
305 static const UINT8 AcpiGbl_ResourceTypes[] =
307 /* Small descriptors */
313 ACPI_SMALL_VARIABLE_LENGTH,
314 ACPI_FIXED_LENGTH,
315 ACPI_SMALL_VARIABLE_LENGTH,
316 ACPI_FIXED_LENGTH,
317 ACPI_FIXED_LENGTH,
318 ACPI_FIXED_LENGTH,
323 ACPI_VARIABLE_LENGTH,
324 ACPI_FIXED_LENGTH,
326 /* Large descriptors */
329 ACPI_FIXED_LENGTH,
330 ACPI_FIXED_LENGTH,
332 ACPI_VARIABLE_LENGTH,
333 ACPI_FIXED_LENGTH,
334 ACPI_FIXED_LENGTH,
335 ACPI_VARIABLE_LENGTH,
336 ACPI_VARIABLE_LENGTH,
337 ACPI_VARIABLE_LENGTH,
338 ACPI_VARIABLE_LENGTH,
339 ACPI_FIXED_LENGTH
343 /*******************************************************************************
345 * FUNCTION: AcpiUtWalkAmlResources
347 * PARAMETERS: Aml - Pointer to the raw AML resource template
348 * AmlLength - Length of the entire template
349 * UserFunction - Called once for each descriptor found. If
350 * NULL, a pointer to the EndTag is returned
351 * Context - Passed to UserFunction
353 * RETURN: Status
355 * DESCRIPTION: Walk a raw AML resource list(buffer). User function called
356 * once for each resource found.
358 ******************************************************************************/
360 ACPI_STATUS
361 AcpiUtWalkAmlResources (
362 UINT8 *Aml,
363 ACPI_SIZE AmlLength,
364 ACPI_WALK_AML_CALLBACK UserFunction,
365 void *Context)
367 ACPI_STATUS Status;
368 UINT8 *EndAml;
369 UINT8 ResourceIndex;
370 UINT32 Length;
371 UINT32 Offset = 0;
374 ACPI_FUNCTION_TRACE (UtWalkAmlResources);
377 /* The absolute minimum resource template is one EndTag descriptor */
379 if (AmlLength < sizeof (AML_RESOURCE_END_TAG))
381 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
384 /* Point to the end of the resource template buffer */
386 EndAml = Aml + AmlLength;
388 /* Walk the byte list, abort on any invalid descriptor type or length */
390 while (Aml < EndAml)
392 /* Validate the Resource Type and Resource Length */
394 Status = AcpiUtValidateResource (Aml, &ResourceIndex);
395 if (ACPI_FAILURE (Status))
397 return_ACPI_STATUS (Status);
400 /* Get the length of this descriptor */
402 Length = AcpiUtGetDescriptorLength (Aml);
404 /* Invoke the user function */
406 if (UserFunction)
408 Status = UserFunction (Aml, Length, Offset, ResourceIndex, Context);
409 if (ACPI_FAILURE (Status))
411 return (Status);
415 /* An EndTag descriptor terminates this resource template */
417 if (AcpiUtGetResourceType (Aml) == ACPI_RESOURCE_NAME_END_TAG)
420 * There must be at least one more byte in the buffer for
421 * the 2nd byte of the EndTag
423 if ((Aml + 1) >= EndAml)
425 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
428 /* Return the pointer to the EndTag if requested */
430 if (!UserFunction)
432 *(void **) Context = Aml;
435 /* Normal exit */
437 return_ACPI_STATUS (AE_OK);
440 Aml += Length;
441 Offset += Length;
444 /* Did not find an EndTag descriptor */
446 return (AE_AML_NO_RESOURCE_END_TAG);
450 /*******************************************************************************
452 * FUNCTION: AcpiUtValidateResource
454 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor
455 * ReturnIndex - Where the resource index is returned. NULL
456 * if the index is not required.
458 * RETURN: Status, and optionally the Index into the global resource tables
460 * DESCRIPTION: Validate an AML resource descriptor by checking the Resource
461 * Type and Resource Length. Returns an index into the global
462 * resource information/dispatch tables for later use.
464 ******************************************************************************/
466 ACPI_STATUS
467 AcpiUtValidateResource (
468 void *Aml,
469 UINT8 *ReturnIndex)
471 UINT8 ResourceType;
472 UINT8 ResourceIndex;
473 ACPI_RS_LENGTH ResourceLength;
474 ACPI_RS_LENGTH MinimumResourceLength;
477 ACPI_FUNCTION_ENTRY ();
481 * 1) Validate the ResourceType field (Byte 0)
483 ResourceType = ACPI_GET8 (Aml);
486 * Byte 0 contains the descriptor name (Resource Type)
487 * Examine the large/small bit in the resource header
489 if (ResourceType & ACPI_RESOURCE_NAME_LARGE)
491 /* Verify the large resource type (name) against the max */
493 if (ResourceType > ACPI_RESOURCE_NAME_LARGE_MAX)
495 return (AE_AML_INVALID_RESOURCE_TYPE);
499 * Large Resource Type -- bits 6:0 contain the name
500 * Translate range 0x80-0x8B to index range 0x10-0x1B
502 ResourceIndex = (UINT8) (ResourceType - 0x70);
504 else
507 * Small Resource Type -- bits 6:3 contain the name
508 * Shift range to index range 0x00-0x0F
510 ResourceIndex = (UINT8)
511 ((ResourceType & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3);
514 /* Check validity of the resource type, zero indicates name is invalid */
516 if (!AcpiGbl_ResourceTypes[ResourceIndex])
518 return (AE_AML_INVALID_RESOURCE_TYPE);
523 * 2) Validate the ResourceLength field. This ensures that the length
524 * is at least reasonable, and guarantees that it is non-zero.
526 ResourceLength = AcpiUtGetResourceLength (Aml);
527 MinimumResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
529 /* Validate based upon the type of resource - fixed length or variable */
531 switch (AcpiGbl_ResourceTypes[ResourceIndex])
533 case ACPI_FIXED_LENGTH:
535 /* Fixed length resource, length must match exactly */
537 if (ResourceLength != MinimumResourceLength)
539 return (AE_AML_BAD_RESOURCE_LENGTH);
541 break;
543 case ACPI_VARIABLE_LENGTH:
545 /* Variable length resource, length must be at least the minimum */
547 if (ResourceLength < MinimumResourceLength)
549 return (AE_AML_BAD_RESOURCE_LENGTH);
551 break;
553 case ACPI_SMALL_VARIABLE_LENGTH:
555 /* Small variable length resource, length can be (Min) or (Min-1) */
557 if ((ResourceLength > MinimumResourceLength) ||
558 (ResourceLength < (MinimumResourceLength - 1)))
560 return (AE_AML_BAD_RESOURCE_LENGTH);
562 break;
564 default:
566 /* Shouldn't happen (because of validation earlier), but be sure */
568 return (AE_AML_INVALID_RESOURCE_TYPE);
571 /* Optionally return the resource table index */
573 if (ReturnIndex)
575 *ReturnIndex = ResourceIndex;
578 return (AE_OK);
582 /*******************************************************************************
584 * FUNCTION: AcpiUtGetResourceType
586 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor
588 * RETURN: The Resource Type with no extraneous bits (except the
589 * Large/Small descriptor bit -- this is left alone)
591 * DESCRIPTION: Extract the Resource Type/Name from the first byte of
592 * a resource descriptor.
594 ******************************************************************************/
596 UINT8
597 AcpiUtGetResourceType (
598 void *Aml)
600 ACPI_FUNCTION_ENTRY ();
604 * Byte 0 contains the descriptor name (Resource Type)
605 * Examine the large/small bit in the resource header
607 if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE)
609 /* Large Resource Type -- bits 6:0 contain the name */
611 return (ACPI_GET8 (Aml));
613 else
615 /* Small Resource Type -- bits 6:3 contain the name */
617 return ((UINT8) (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_SMALL_MASK));
622 /*******************************************************************************
624 * FUNCTION: AcpiUtGetResourceLength
626 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor
628 * RETURN: Byte Length
630 * DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By
631 * definition, this does not include the size of the descriptor
632 * header or the length field itself.
634 ******************************************************************************/
636 UINT16
637 AcpiUtGetResourceLength (
638 void *Aml)
640 ACPI_RS_LENGTH ResourceLength;
643 ACPI_FUNCTION_ENTRY ();
647 * Byte 0 contains the descriptor name (Resource Type)
648 * Examine the large/small bit in the resource header
650 if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE)
652 /* Large Resource type -- bytes 1-2 contain the 16-bit length */
654 ACPI_MOVE_16_TO_16 (&ResourceLength, ACPI_ADD_PTR (UINT8, Aml, 1));
657 else
659 /* Small Resource type -- bits 2:0 of byte 0 contain the length */
661 ResourceLength = (UINT16) (ACPI_GET8 (Aml) &
662 ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK);
665 return (ResourceLength);
669 /*******************************************************************************
671 * FUNCTION: AcpiUtGetResourceHeaderLength
673 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor
675 * RETURN: Length of the AML header (depends on large/small descriptor)
677 * DESCRIPTION: Get the length of the header for this resource.
679 ******************************************************************************/
681 UINT8
682 AcpiUtGetResourceHeaderLength (
683 void *Aml)
685 ACPI_FUNCTION_ENTRY ();
688 /* Examine the large/small bit in the resource header */
690 if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE)
692 return (sizeof (AML_RESOURCE_LARGE_HEADER));
694 else
696 return (sizeof (AML_RESOURCE_SMALL_HEADER));
701 /*******************************************************************************
703 * FUNCTION: AcpiUtGetDescriptorLength
705 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor
707 * RETURN: Byte length
709 * DESCRIPTION: Get the total byte length of a raw AML descriptor, including the
710 * length of the descriptor header and the length field itself.
711 * Used to walk descriptor lists.
713 ******************************************************************************/
715 UINT32
716 AcpiUtGetDescriptorLength (
717 void *Aml)
719 ACPI_FUNCTION_ENTRY ();
723 * Get the Resource Length (does not include header length) and add
724 * the header length (depends on if this is a small or large resource)
726 return (AcpiUtGetResourceLength (Aml) +
727 AcpiUtGetResourceHeaderLength (Aml));
731 /*******************************************************************************
733 * FUNCTION: AcpiUtGetResourceEndTag
735 * PARAMETERS: ObjDesc - The resource template buffer object
736 * EndTag - Where the pointer to the EndTag is returned
738 * RETURN: Status, pointer to the end tag
740 * DESCRIPTION: Find the EndTag resource descriptor in an AML resource template
741 * Note: allows a buffer length of zero.
743 ******************************************************************************/
745 ACPI_STATUS
746 AcpiUtGetResourceEndTag (
747 ACPI_OPERAND_OBJECT *ObjDesc,
748 UINT8 **EndTag)
750 ACPI_STATUS Status;
753 ACPI_FUNCTION_TRACE (UtGetResourceEndTag);
756 /* Allow a buffer length of zero */
758 if (!ObjDesc->Buffer.Length)
760 *EndTag = ObjDesc->Buffer.Pointer;
761 return_ACPI_STATUS (AE_OK);
764 /* Validate the template and get a pointer to the EndTag */
766 Status = AcpiUtWalkAmlResources (ObjDesc->Buffer.Pointer,
767 ObjDesc->Buffer.Length, NULL, EndTag);
769 return_ACPI_STATUS (Status);