![]() |
|
|||
File indexing completed on 2025-05-11 08:24:04
0001 /******************************************************************************* 0002 * 0003 * Module Name: utresrc - Resource management utilities 0004 * 0005 ******************************************************************************/ 0006 0007 /****************************************************************************** 0008 * 0009 * 1. Copyright Notice 0010 * 0011 * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp. 0012 * All rights reserved. 0013 * 0014 * 2. License 0015 * 0016 * 2.1. This is your license from Intel Corp. under its intellectual property 0017 * rights. You may have additional license terms from the party that provided 0018 * you this software, covering your right to use that party's intellectual 0019 * property rights. 0020 * 0021 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 0022 * copy of the source code appearing in this file ("Covered Code") an 0023 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 0024 * base code distributed originally by Intel ("Original Intel Code") to copy, 0025 * make derivatives, distribute, use and display any portion of the Covered 0026 * Code in any form, with the right to sublicense such rights; and 0027 * 0028 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 0029 * license (with the right to sublicense), under only those claims of Intel 0030 * patents that are infringed by the Original Intel Code, to make, use, sell, 0031 * offer to sell, and import the Covered Code and derivative works thereof 0032 * solely to the minimum extent necessary to exercise the above copyright 0033 * license, and in no event shall the patent license extend to any additions 0034 * to or modifications of the Original Intel Code. No other license or right 0035 * is granted directly or by implication, estoppel or otherwise; 0036 * 0037 * The above copyright and patent license is granted only if the following 0038 * conditions are met: 0039 * 0040 * 3. Conditions 0041 * 0042 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 0043 * Redistribution of source code of any substantial portion of the Covered 0044 * Code or modification with rights to further distribute source must include 0045 * the above Copyright Notice, the above License, this list of Conditions, 0046 * and the following Disclaimer and Export Compliance provision. In addition, 0047 * Licensee must cause all Covered Code to which Licensee contributes to 0048 * contain a file documenting the changes Licensee made to create that Covered 0049 * Code and the date of any change. Licensee must include in that file the 0050 * documentation of any changes made by any predecessor Licensee. Licensee 0051 * must include a prominent statement that the modification is derived, 0052 * directly or indirectly, from Original Intel Code. 0053 * 0054 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 0055 * Redistribution of source code of any substantial portion of the Covered 0056 * Code or modification without rights to further distribute source must 0057 * include the following Disclaimer and Export Compliance provision in the 0058 * documentation and/or other materials provided with distribution. In 0059 * addition, Licensee may not authorize further sublicense of source of any 0060 * portion of the Covered Code, and must include terms to the effect that the 0061 * license from Licensee to its licensee is limited to the intellectual 0062 * property embodied in the software Licensee provides to its licensee, and 0063 * not to intellectual property embodied in modifications its licensee may 0064 * make. 0065 * 0066 * 3.3. Redistribution of Executable. Redistribution in executable form of any 0067 * substantial portion of the Covered Code or modification must reproduce the 0068 * above Copyright Notice, and the following Disclaimer and Export Compliance 0069 * provision in the documentation and/or other materials provided with the 0070 * distribution. 0071 * 0072 * 3.4. Intel retains all right, title, and interest in and to the Original 0073 * Intel Code. 0074 * 0075 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 0076 * Intel shall be used in advertising or otherwise to promote the sale, use or 0077 * other dealings in products derived from or relating to the Covered Code 0078 * without prior written authorization from Intel. 0079 * 0080 * 4. Disclaimer and Export Compliance 0081 * 0082 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 0083 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 0084 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 0085 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 0086 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 0087 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 0088 * PARTICULAR PURPOSE. 0089 * 0090 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 0091 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 0092 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 0093 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 0094 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 0095 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 0096 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 0097 * LIMITED REMEDY. 0098 * 0099 * 4.3. Licensee shall not export, either directly or indirectly, any of this 0100 * software or system incorporating such software without first obtaining any 0101 * required license or other approval from the U. S. Department of Commerce or 0102 * any other agency or department of the United States Government. In the 0103 * event Licensee exports any such software from the United States or 0104 * re-exports any such software from a foreign destination, Licensee shall 0105 * ensure that the distribution and export/re-export of the software is in 0106 * compliance with all laws, regulations, orders, or other restrictions of the 0107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 0108 * any of its subsidiaries will export/re-export any technical data, process, 0109 * software, or service, directly or indirectly, to any country for which the 0110 * United States government or any agency thereof requires an export license, 0111 * other governmental approval, or letter of assurance, without first obtaining 0112 * such license, approval or letter. 0113 * 0114 ***************************************************************************** 0115 * 0116 * Alternatively, you may choose to be licensed under the terms of the 0117 * following license: 0118 * 0119 * Redistribution and use in source and binary forms, with or without 0120 * modification, are permitted provided that the following conditions 0121 * are met: 0122 * 1. Redistributions of source code must retain the above copyright 0123 * notice, this list of conditions, and the following disclaimer, 0124 * without modification. 0125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 0126 * substantially similar to the "NO WARRANTY" disclaimer below 0127 * ("Disclaimer") and any redistribution must be conditioned upon 0128 * including a substantially similar Disclaimer requirement for further 0129 * binary redistribution. 0130 * 3. Neither the names of the above-listed copyright holders nor the names 0131 * of any contributors may be used to endorse or promote products derived 0132 * from this software without specific prior written permission. 0133 * 0134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0145 * 0146 * Alternatively, you may choose to be licensed under the terms of the 0147 * GNU General Public License ("GPL") version 2 as published by the Free 0148 * Software Foundation. 0149 * 0150 *****************************************************************************/ 0151 0152 #include "acpi.h" 0153 #include "accommon.h" 0154 #include "acresrc.h" 0155 0156 0157 #define _COMPONENT ACPI_UTILITIES 0158 ACPI_MODULE_NAME ("utresrc") 0159 0160 0161 /* 0162 * Base sizes of the raw AML resource descriptors, indexed by resource type. 0163 * Zero indicates a reserved (and therefore invalid) resource type. 0164 */ 0165 const UINT8 AcpiGbl_ResourceAmlSizes[] = 0166 { 0167 /* Small descriptors */ 0168 0169 0, 0170 0, 0171 0, 0172 0, 0173 ACPI_AML_SIZE_SMALL (AML_RESOURCE_IRQ), 0174 ACPI_AML_SIZE_SMALL (AML_RESOURCE_DMA), 0175 ACPI_AML_SIZE_SMALL (AML_RESOURCE_START_DEPENDENT), 0176 ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_DEPENDENT), 0177 ACPI_AML_SIZE_SMALL (AML_RESOURCE_IO), 0178 ACPI_AML_SIZE_SMALL (AML_RESOURCE_FIXED_IO), 0179 ACPI_AML_SIZE_SMALL (AML_RESOURCE_FIXED_DMA), 0180 0, 0181 0, 0182 0, 0183 ACPI_AML_SIZE_SMALL (AML_RESOURCE_VENDOR_SMALL), 0184 ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_TAG), 0185 0186 /* Large descriptors */ 0187 0188 0, 0189 ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY24), 0190 ACPI_AML_SIZE_LARGE (AML_RESOURCE_GENERIC_REGISTER), 0191 0, 0192 ACPI_AML_SIZE_LARGE (AML_RESOURCE_VENDOR_LARGE), 0193 ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY32), 0194 ACPI_AML_SIZE_LARGE (AML_RESOURCE_FIXED_MEMORY32), 0195 ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS32), 0196 ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS16), 0197 ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_IRQ), 0198 ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS64), 0199 ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_ADDRESS64), 0200 ACPI_AML_SIZE_LARGE (AML_RESOURCE_GPIO), 0201 ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_FUNCTION), 0202 ACPI_AML_SIZE_LARGE (AML_RESOURCE_COMMON_SERIALBUS), 0203 ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_CONFIG), 0204 ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_GROUP), 0205 ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_GROUP_FUNCTION), 0206 ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_GROUP_CONFIG), 0207 ACPI_AML_SIZE_LARGE (AML_RESOURCE_CLOCK_INPUT), 0208 0209 }; 0210 0211 const UINT8 AcpiGbl_ResourceAmlSerialBusSizes[] = 0212 { 0213 0, 0214 ACPI_AML_SIZE_LARGE (AML_RESOURCE_I2C_SERIALBUS), 0215 ACPI_AML_SIZE_LARGE (AML_RESOURCE_SPI_SERIALBUS), 0216 ACPI_AML_SIZE_LARGE (AML_RESOURCE_UART_SERIALBUS), 0217 ACPI_AML_SIZE_LARGE (AML_RESOURCE_CSI2_SERIALBUS), 0218 }; 0219 0220 0221 /* 0222 * Resource types, used to validate the resource length field. 0223 * The length of fixed-length types must match exactly, variable 0224 * lengths must meet the minimum required length, etc. 0225 * Zero indicates a reserved (and therefore invalid) resource type. 0226 */ 0227 static const UINT8 AcpiGbl_ResourceTypes[] = 0228 { 0229 /* Small descriptors */ 0230 0231 0, 0232 0, 0233 0, 0234 0, 0235 ACPI_SMALL_VARIABLE_LENGTH, /* 04 IRQ */ 0236 ACPI_FIXED_LENGTH, /* 05 DMA */ 0237 ACPI_SMALL_VARIABLE_LENGTH, /* 06 StartDependentFunctions */ 0238 ACPI_FIXED_LENGTH, /* 07 EndDependentFunctions */ 0239 ACPI_FIXED_LENGTH, /* 08 IO */ 0240 ACPI_FIXED_LENGTH, /* 09 FixedIO */ 0241 ACPI_FIXED_LENGTH, /* 0A FixedDMA */ 0242 0, 0243 0, 0244 0, 0245 ACPI_VARIABLE_LENGTH, /* 0E VendorShort */ 0246 ACPI_FIXED_LENGTH, /* 0F EndTag */ 0247 0248 /* Large descriptors */ 0249 0250 0, 0251 ACPI_FIXED_LENGTH, /* 01 Memory24 */ 0252 ACPI_FIXED_LENGTH, /* 02 GenericRegister */ 0253 0, 0254 ACPI_VARIABLE_LENGTH, /* 04 VendorLong */ 0255 ACPI_FIXED_LENGTH, /* 05 Memory32 */ 0256 ACPI_FIXED_LENGTH, /* 06 Memory32Fixed */ 0257 ACPI_VARIABLE_LENGTH, /* 07 Dword* address */ 0258 ACPI_VARIABLE_LENGTH, /* 08 Word* address */ 0259 ACPI_VARIABLE_LENGTH, /* 09 ExtendedIRQ */ 0260 ACPI_VARIABLE_LENGTH, /* 0A Qword* address */ 0261 ACPI_FIXED_LENGTH, /* 0B Extended* address */ 0262 ACPI_VARIABLE_LENGTH, /* 0C Gpio* */ 0263 ACPI_VARIABLE_LENGTH, /* 0D PinFunction */ 0264 ACPI_VARIABLE_LENGTH, /* 0E *SerialBus */ 0265 ACPI_VARIABLE_LENGTH, /* 0F PinConfig */ 0266 ACPI_VARIABLE_LENGTH, /* 10 PinGroup */ 0267 ACPI_VARIABLE_LENGTH, /* 11 PinGroupFunction */ 0268 ACPI_VARIABLE_LENGTH, /* 12 PinGroupConfig */ 0269 ACPI_VARIABLE_LENGTH, /* 13 ClockInput */ 0270 }; 0271 0272 0273 /******************************************************************************* 0274 * 0275 * FUNCTION: AcpiUtWalkAmlResources 0276 * 0277 * PARAMETERS: WalkState - Current walk info 0278 * PARAMETERS: Aml - Pointer to the raw AML resource template 0279 * AmlLength - Length of the entire template 0280 * UserFunction - Called once for each descriptor found. If 0281 * NULL, a pointer to the EndTag is returned 0282 * Context - Passed to UserFunction 0283 * 0284 * RETURN: Status 0285 * 0286 * DESCRIPTION: Walk a raw AML resource list(buffer). User function called 0287 * once for each resource found. 0288 * 0289 ******************************************************************************/ 0290 0291 ACPI_STATUS 0292 AcpiUtWalkAmlResources ( 0293 ACPI_WALK_STATE *WalkState, 0294 UINT8 *Aml, 0295 ACPI_SIZE AmlLength, 0296 ACPI_WALK_AML_CALLBACK UserFunction, 0297 void **Context) 0298 { 0299 ACPI_STATUS Status; 0300 UINT8 *EndAml; 0301 UINT8 ResourceIndex; 0302 UINT32 Length; 0303 UINT32 Offset = 0; 0304 UINT8 EndTag[2] = {0x79, 0x00}; 0305 0306 0307 ACPI_FUNCTION_TRACE (UtWalkAmlResources); 0308 0309 0310 /* The absolute minimum resource template is one EndTag descriptor */ 0311 0312 if (AmlLength < sizeof (AML_RESOURCE_END_TAG)) 0313 { 0314 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 0315 } 0316 0317 /* Point to the end of the resource template buffer */ 0318 0319 EndAml = Aml + AmlLength; 0320 0321 /* Walk the byte list, abort on any invalid descriptor type or length */ 0322 0323 while (Aml < EndAml) 0324 { 0325 /* Validate the Resource Type and Resource Length */ 0326 0327 Status = AcpiUtValidateResource (WalkState, Aml, &ResourceIndex); 0328 if (ACPI_FAILURE (Status)) 0329 { 0330 /* 0331 * Exit on failure. Cannot continue because the descriptor 0332 * length may be bogus also. 0333 */ 0334 return_ACPI_STATUS (Status); 0335 } 0336 0337 /* Get the length of this descriptor */ 0338 0339 Length = AcpiUtGetDescriptorLength (Aml); 0340 0341 /* Invoke the user function */ 0342 0343 if (UserFunction) 0344 { 0345 Status = UserFunction ( 0346 Aml, Length, Offset, ResourceIndex, Context); 0347 if (ACPI_FAILURE (Status)) 0348 { 0349 return_ACPI_STATUS (Status); 0350 } 0351 } 0352 0353 /* An EndTag descriptor terminates this resource template */ 0354 0355 if (AcpiUtGetResourceType (Aml) == ACPI_RESOURCE_NAME_END_TAG) 0356 { 0357 /* 0358 * There must be at least one more byte in the buffer for 0359 * the 2nd byte of the EndTag 0360 */ 0361 if ((Aml + 1) >= EndAml) 0362 { 0363 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 0364 } 0365 0366 /* 0367 * Don't attempt to perform any validation on the 2nd byte. 0368 * Although all known ASL compilers insert a zero for the 2nd 0369 * byte, it can also be a checksum (as per the ACPI spec), 0370 * and this is occasionally seen in the field. July 2017. 0371 */ 0372 0373 /* Return the pointer to the EndTag if requested */ 0374 0375 if (!UserFunction) 0376 { 0377 *Context = Aml; 0378 } 0379 0380 /* Normal exit */ 0381 0382 return_ACPI_STATUS (AE_OK); 0383 } 0384 0385 Aml += Length; 0386 Offset += Length; 0387 } 0388 0389 /* Did not find an EndTag descriptor */ 0390 0391 if (UserFunction) 0392 { 0393 /* Insert an EndTag anyway. AcpiRsGetListLength always leaves room */ 0394 0395 (void) AcpiUtValidateResource (WalkState, EndTag, &ResourceIndex); 0396 Status = UserFunction (EndTag, 2, Offset, ResourceIndex, Context); 0397 if (ACPI_FAILURE (Status)) 0398 { 0399 return_ACPI_STATUS (Status); 0400 } 0401 } 0402 0403 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 0404 } 0405 0406 0407 /******************************************************************************* 0408 * 0409 * FUNCTION: AcpiUtValidateResource 0410 * 0411 * PARAMETERS: WalkState - Current walk info 0412 * Aml - Pointer to the raw AML resource descriptor 0413 * ReturnIndex - Where the resource index is returned. NULL 0414 * if the index is not required. 0415 * 0416 * RETURN: Status, and optionally the Index into the global resource tables 0417 * 0418 * DESCRIPTION: Validate an AML resource descriptor by checking the Resource 0419 * Type and Resource Length. Returns an index into the global 0420 * resource information/dispatch tables for later use. 0421 * 0422 ******************************************************************************/ 0423 0424 ACPI_STATUS 0425 AcpiUtValidateResource ( 0426 ACPI_WALK_STATE *WalkState, 0427 void *Aml, 0428 UINT8 *ReturnIndex) 0429 { 0430 AML_RESOURCE *AmlResource; 0431 UINT8 ResourceType; 0432 UINT8 ResourceIndex; 0433 ACPI_RS_LENGTH ResourceLength; 0434 ACPI_RS_LENGTH MinimumResourceLength; 0435 0436 0437 ACPI_FUNCTION_ENTRY (); 0438 0439 0440 /* 0441 * 1) Validate the ResourceType field (Byte 0) 0442 */ 0443 ResourceType = ACPI_GET8 (Aml); 0444 0445 /* 0446 * Byte 0 contains the descriptor name (Resource Type) 0447 * Examine the large/small bit in the resource header 0448 */ 0449 if (ResourceType & ACPI_RESOURCE_NAME_LARGE) 0450 { 0451 /* Verify the large resource type (name) against the max */ 0452 0453 if (ResourceType > ACPI_RESOURCE_NAME_LARGE_MAX) 0454 { 0455 goto InvalidResource; 0456 } 0457 0458 /* 0459 * Large Resource Type -- bits 6:0 contain the name 0460 * Translate range 0x80-0x8B to index range 0x10-0x1B 0461 */ 0462 ResourceIndex = (UINT8) (ResourceType - 0x70); 0463 } 0464 else 0465 { 0466 /* 0467 * Small Resource Type -- bits 6:3 contain the name 0468 * Shift range to index range 0x00-0x0F 0469 */ 0470 ResourceIndex = (UINT8) 0471 ((ResourceType & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3); 0472 } 0473 0474 /* 0475 * Check validity of the resource type, via AcpiGbl_ResourceTypes. 0476 * Zero indicates an invalid resource. 0477 */ 0478 if (!AcpiGbl_ResourceTypes[ResourceIndex]) 0479 { 0480 goto InvalidResource; 0481 } 0482 0483 /* 0484 * Validate the ResourceLength field. This ensures that the length 0485 * is at least reasonable, and guarantees that it is non-zero. 0486 */ 0487 ResourceLength = AcpiUtGetResourceLength (Aml); 0488 MinimumResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex]; 0489 0490 /* Validate based upon the type of resource - fixed length or variable */ 0491 0492 switch (AcpiGbl_ResourceTypes[ResourceIndex]) 0493 { 0494 case ACPI_FIXED_LENGTH: 0495 0496 /* Fixed length resource, length must match exactly */ 0497 0498 if (ResourceLength != MinimumResourceLength) 0499 { 0500 goto BadResourceLength; 0501 } 0502 break; 0503 0504 case ACPI_VARIABLE_LENGTH: 0505 0506 /* Variable length resource, length must be at least the minimum */ 0507 0508 if (ResourceLength < MinimumResourceLength) 0509 { 0510 goto BadResourceLength; 0511 } 0512 break; 0513 0514 case ACPI_SMALL_VARIABLE_LENGTH: 0515 0516 /* Small variable length resource, length can be (Min) or (Min-1) */ 0517 0518 if ((ResourceLength > MinimumResourceLength) || 0519 (ResourceLength < (MinimumResourceLength - 1))) 0520 { 0521 goto BadResourceLength; 0522 } 0523 break; 0524 0525 default: 0526 0527 /* Shouldn't happen (because of validation earlier), but be sure */ 0528 0529 goto InvalidResource; 0530 } 0531 0532 AmlResource = ACPI_CAST_PTR (AML_RESOURCE, Aml); 0533 if (ResourceType == ACPI_RESOURCE_NAME_SERIAL_BUS) 0534 { 0535 /* Avoid undefined behavior: member access within misaligned address */ 0536 0537 AML_RESOURCE_COMMON_SERIALBUS CommonSerialBus; 0538 memcpy(&CommonSerialBus, AmlResource, sizeof(CommonSerialBus)); 0539 0540 /* Validate the BusType field */ 0541 0542 if ((CommonSerialBus.Type == 0) || 0543 (CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE)) 0544 { 0545 if (WalkState) 0546 { 0547 ACPI_ERROR ((AE_INFO, 0548 "Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X", 0549 CommonSerialBus.Type)); 0550 } 0551 return (AE_AML_INVALID_RESOURCE_TYPE); 0552 } 0553 } 0554 0555 /* Optionally return the resource table index */ 0556 0557 if (ReturnIndex) 0558 { 0559 *ReturnIndex = ResourceIndex; 0560 } 0561 0562 return (AE_OK); 0563 0564 0565 InvalidResource: 0566 0567 if (WalkState) 0568 { 0569 ACPI_ERROR ((AE_INFO, 0570 "Invalid/unsupported resource descriptor: Type 0x%2.2X", 0571 ResourceType)); 0572 } 0573 return (AE_AML_INVALID_RESOURCE_TYPE); 0574 0575 BadResourceLength: 0576 0577 if (WalkState) 0578 { 0579 ACPI_ERROR ((AE_INFO, 0580 "Invalid resource descriptor length: Type " 0581 "0x%2.2X, Length 0x%4.4X, MinLength 0x%4.4X", 0582 ResourceType, ResourceLength, MinimumResourceLength)); 0583 } 0584 return (AE_AML_BAD_RESOURCE_LENGTH); 0585 } 0586 0587 0588 /******************************************************************************* 0589 * 0590 * FUNCTION: AcpiUtGetResourceType 0591 * 0592 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor 0593 * 0594 * RETURN: The Resource Type with no extraneous bits (except the 0595 * Large/Small descriptor bit -- this is left alone) 0596 * 0597 * DESCRIPTION: Extract the Resource Type/Name from the first byte of 0598 * a resource descriptor. 0599 * 0600 ******************************************************************************/ 0601 0602 UINT8 0603 AcpiUtGetResourceType ( 0604 void *Aml) 0605 { 0606 ACPI_FUNCTION_ENTRY (); 0607 0608 0609 /* 0610 * Byte 0 contains the descriptor name (Resource Type) 0611 * Examine the large/small bit in the resource header 0612 */ 0613 if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE) 0614 { 0615 /* Large Resource Type -- bits 6:0 contain the name */ 0616 0617 return (ACPI_GET8 (Aml)); 0618 } 0619 else 0620 { 0621 /* Small Resource Type -- bits 6:3 contain the name */ 0622 0623 return ((UINT8) (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_SMALL_MASK)); 0624 } 0625 } 0626 0627 0628 /******************************************************************************* 0629 * 0630 * FUNCTION: AcpiUtGetResourceLength 0631 * 0632 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor 0633 * 0634 * RETURN: Byte Length 0635 * 0636 * DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By 0637 * definition, this does not include the size of the descriptor 0638 * header or the length field itself. 0639 * 0640 ******************************************************************************/ 0641 0642 UINT16 0643 AcpiUtGetResourceLength ( 0644 void *Aml) 0645 { 0646 ACPI_RS_LENGTH ResourceLength; 0647 0648 0649 ACPI_FUNCTION_ENTRY (); 0650 0651 0652 /* 0653 * Byte 0 contains the descriptor name (Resource Type) 0654 * Examine the large/small bit in the resource header 0655 */ 0656 if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE) 0657 { 0658 /* Large Resource type -- bytes 1-2 contain the 16-bit length */ 0659 0660 ACPI_MOVE_16_TO_16 (&ResourceLength, ACPI_ADD_PTR (UINT8, Aml, 1)); 0661 0662 } 0663 else 0664 { 0665 /* Small Resource type -- bits 2:0 of byte 0 contain the length */ 0666 0667 ResourceLength = (UINT16) (ACPI_GET8 (Aml) & 0668 ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK); 0669 } 0670 0671 return (ResourceLength); 0672 } 0673 0674 0675 /******************************************************************************* 0676 * 0677 * FUNCTION: AcpiUtGetResourceHeaderLength 0678 * 0679 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor 0680 * 0681 * RETURN: Length of the AML header (depends on large/small descriptor) 0682 * 0683 * DESCRIPTION: Get the length of the header for this resource. 0684 * 0685 ******************************************************************************/ 0686 0687 UINT8 0688 AcpiUtGetResourceHeaderLength ( 0689 void *Aml) 0690 { 0691 ACPI_FUNCTION_ENTRY (); 0692 0693 0694 /* Examine the large/small bit in the resource header */ 0695 0696 if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE) 0697 { 0698 return (sizeof (AML_RESOURCE_LARGE_HEADER)); 0699 } 0700 else 0701 { 0702 return (sizeof (AML_RESOURCE_SMALL_HEADER)); 0703 } 0704 } 0705 0706 0707 /******************************************************************************* 0708 * 0709 * FUNCTION: AcpiUtGetDescriptorLength 0710 * 0711 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor 0712 * 0713 * RETURN: Byte length 0714 * 0715 * DESCRIPTION: Get the total byte length of a raw AML descriptor, including the 0716 * length of the descriptor header and the length field itself. 0717 * Used to walk descriptor lists. 0718 * 0719 ******************************************************************************/ 0720 0721 UINT32 0722 AcpiUtGetDescriptorLength ( 0723 void *Aml) 0724 { 0725 ACPI_FUNCTION_ENTRY (); 0726 0727 0728 /* 0729 * Get the Resource Length (does not include header length) and add 0730 * the header length (depends on if this is a small or large resource) 0731 */ 0732 return (AcpiUtGetResourceLength (Aml) + 0733 AcpiUtGetResourceHeaderLength (Aml)); 0734 } 0735 0736 0737 /******************************************************************************* 0738 * 0739 * FUNCTION: AcpiUtGetResourceEndTag 0740 * 0741 * PARAMETERS: ObjDesc - The resource template buffer object 0742 * EndTag - Where the pointer to the EndTag is returned 0743 * 0744 * RETURN: Status, pointer to the end tag 0745 * 0746 * DESCRIPTION: Find the EndTag resource descriptor in an AML resource template 0747 * Note: allows a buffer length of zero. 0748 * 0749 ******************************************************************************/ 0750 0751 ACPI_STATUS 0752 AcpiUtGetResourceEndTag ( 0753 ACPI_OPERAND_OBJECT *ObjDesc, 0754 UINT8 **EndTag) 0755 { 0756 ACPI_STATUS Status; 0757 0758 0759 ACPI_FUNCTION_TRACE (UtGetResourceEndTag); 0760 0761 0762 /* Allow a buffer length of zero */ 0763 0764 if (!ObjDesc->Buffer.Length) 0765 { 0766 *EndTag = ObjDesc->Buffer.Pointer; 0767 return_ACPI_STATUS (AE_OK); 0768 } 0769 0770 /* Validate the template and get a pointer to the EndTag */ 0771 0772 Status = AcpiUtWalkAmlResources (NULL, ObjDesc->Buffer.Pointer, 0773 ObjDesc->Buffer.Length, NULL, (void **) EndTag); 0774 0775 return_ACPI_STATUS (Status); 0776 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |