![]() |
|
|||
File indexing completed on 2025-05-11 08:24:02
0001 /****************************************************************************** 0002 * 0003 * Module Name: exconcat - Concatenate-type AML operators 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 0087 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 0088 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 0089 * PARTICULAR PURPOSE. 0090 * 0091 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 0092 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 0093 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 0094 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 0095 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 0096 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 0097 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 0098 * LIMITED REMEDY. 0099 * 0100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 0101 * software or system incorporating such software without first obtaining any 0102 * required license or other approval from the U. S. Department of Commerce or 0103 * any other agency or department of the United States Government. In the 0104 * event Licensee exports any such software from the United States or 0105 * re-exports any such software from a foreign destination, Licensee shall 0106 * ensure that the distribution and export/re-export of the software is in 0107 * compliance with all laws, regulations, orders, or other restrictions of the 0108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 0109 * any of its subsidiaries will export/re-export any technical data, process, 0110 * software, or service, directly or indirectly, to any country for which the 0111 * United States government or any agency thereof requires an export license, 0112 * other governmental approval, or letter of assurance, without first obtaining 0113 * such license, approval or letter. 0114 * 0115 ***************************************************************************** 0116 * 0117 * Alternatively, you may choose to be licensed under the terms of the 0118 * following license: 0119 * 0120 * Redistribution and use in source and binary forms, with or without 0121 * modification, are permitted provided that the following conditions 0122 * are met: 0123 * 1. Redistributions of source code must retain the above copyright 0124 * notice, this list of conditions, and the following disclaimer, 0125 * without modification. 0126 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 0127 * substantially similar to the "NO WARRANTY" disclaimer below 0128 * ("Disclaimer") and any redistribution must be conditioned upon 0129 * including a substantially similar Disclaimer requirement for further 0130 * binary redistribution. 0131 * 3. Neither the names of the above-listed copyright holders nor the names 0132 * of any contributors may be used to endorse or promote products derived 0133 * from this software without specific prior written permission. 0134 * 0135 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0136 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0137 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0138 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0139 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0140 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0141 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0142 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0143 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0144 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0145 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0146 * 0147 * Alternatively, you may choose to be licensed under the terms of the 0148 * GNU General Public License ("GPL") version 2 as published by the Free 0149 * Software Foundation. 0150 * 0151 *****************************************************************************/ 0152 0153 #include "acpi.h" 0154 #include "accommon.h" 0155 #include "acinterp.h" 0156 #include "amlresrc.h" 0157 0158 0159 #define _COMPONENT ACPI_EXECUTER 0160 ACPI_MODULE_NAME ("exconcat") 0161 0162 /* Local Prototypes */ 0163 0164 static ACPI_STATUS 0165 AcpiExConvertToObjectTypeString ( 0166 ACPI_OPERAND_OBJECT *ObjDesc, 0167 ACPI_OPERAND_OBJECT **ResultDesc); 0168 0169 0170 /******************************************************************************* 0171 * 0172 * FUNCTION: AcpiExDoConcatenate 0173 * 0174 * PARAMETERS: Operand0 - First source object 0175 * Operand1 - Second source object 0176 * ActualReturnDesc - Where to place the return object 0177 * WalkState - Current walk state 0178 * 0179 * RETURN: Status 0180 * 0181 * DESCRIPTION: Concatenate two objects with the ACPI-defined conversion 0182 * rules as necessary. 0183 * NOTE: 0184 * Per the ACPI spec (up to 6.1), Concatenate only supports Integer, 0185 * String, and Buffer objects. However, we support all objects here 0186 * as an extension. This improves the usefulness of both Concatenate 0187 * and the Printf/Fprintf macros. The extension returns a string 0188 * describing the object type for the other objects. 0189 * 02/2016. 0190 * 0191 ******************************************************************************/ 0192 0193 ACPI_STATUS 0194 AcpiExDoConcatenate ( 0195 ACPI_OPERAND_OBJECT *Operand0, 0196 ACPI_OPERAND_OBJECT *Operand1, 0197 ACPI_OPERAND_OBJECT **ActualReturnDesc, 0198 ACPI_WALK_STATE *WalkState) 0199 { 0200 ACPI_OPERAND_OBJECT *LocalOperand0 = Operand0; 0201 ACPI_OPERAND_OBJECT *LocalOperand1 = Operand1; 0202 ACPI_OPERAND_OBJECT *TempOperand1 = NULL; 0203 ACPI_OPERAND_OBJECT *ReturnDesc; 0204 char *Buffer; 0205 ACPI_OBJECT_TYPE Operand0Type; 0206 ACPI_OBJECT_TYPE Operand1Type; 0207 ACPI_STATUS Status; 0208 0209 0210 ACPI_FUNCTION_TRACE (ExDoConcatenate); 0211 0212 0213 /* Operand 0 preprocessing */ 0214 0215 switch (Operand0->Common.Type) 0216 { 0217 case ACPI_TYPE_INTEGER: 0218 case ACPI_TYPE_STRING: 0219 case ACPI_TYPE_BUFFER: 0220 0221 Operand0Type = Operand0->Common.Type; 0222 break; 0223 0224 default: 0225 0226 /* For all other types, get the "object type" string */ 0227 0228 Status = AcpiExConvertToObjectTypeString ( 0229 Operand0, &LocalOperand0); 0230 if (ACPI_FAILURE (Status)) 0231 { 0232 goto Cleanup; 0233 } 0234 0235 Operand0Type = ACPI_TYPE_STRING; 0236 break; 0237 } 0238 0239 /* Operand 1 preprocessing */ 0240 0241 switch (Operand1->Common.Type) 0242 { 0243 case ACPI_TYPE_INTEGER: 0244 case ACPI_TYPE_STRING: 0245 case ACPI_TYPE_BUFFER: 0246 0247 Operand1Type = Operand1->Common.Type; 0248 break; 0249 0250 default: 0251 0252 /* For all other types, get the "object type" string */ 0253 0254 Status = AcpiExConvertToObjectTypeString ( 0255 Operand1, &LocalOperand1); 0256 if (ACPI_FAILURE (Status)) 0257 { 0258 goto Cleanup; 0259 } 0260 0261 Operand1Type = ACPI_TYPE_STRING; 0262 break; 0263 } 0264 0265 /* 0266 * Convert the second operand if necessary. The first operand (0) 0267 * determines the type of the second operand (1) (See the Data Types 0268 * section of the ACPI specification). Both object types are 0269 * guaranteed to be either Integer/String/Buffer by the operand 0270 * resolution mechanism. 0271 */ 0272 switch (Operand0Type) 0273 { 0274 case ACPI_TYPE_INTEGER: 0275 0276 Status = AcpiExConvertToInteger (LocalOperand1, &TempOperand1, 0277 ACPI_IMPLICIT_CONVERSION); 0278 break; 0279 0280 case ACPI_TYPE_BUFFER: 0281 0282 Status = AcpiExConvertToBuffer (LocalOperand1, &TempOperand1); 0283 break; 0284 0285 case ACPI_TYPE_STRING: 0286 0287 switch (Operand1Type) 0288 { 0289 case ACPI_TYPE_INTEGER: 0290 case ACPI_TYPE_STRING: 0291 case ACPI_TYPE_BUFFER: 0292 0293 /* Other types have already been converted to string */ 0294 0295 Status = AcpiExConvertToString ( 0296 LocalOperand1, &TempOperand1, ACPI_IMPLICIT_CONVERT_HEX); 0297 break; 0298 0299 default: 0300 0301 Status = AE_OK; 0302 break; 0303 } 0304 break; 0305 0306 default: 0307 0308 ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X", 0309 Operand0->Common.Type)); 0310 Status = AE_AML_INTERNAL; 0311 } 0312 0313 if (ACPI_FAILURE (Status)) 0314 { 0315 goto Cleanup; 0316 } 0317 0318 /* Take care with any newly created operand objects */ 0319 0320 if ((LocalOperand1 != Operand1) && 0321 (LocalOperand1 != TempOperand1)) 0322 { 0323 AcpiUtRemoveReference (LocalOperand1); 0324 } 0325 0326 LocalOperand1 = TempOperand1; 0327 0328 /* 0329 * Both operands are now known to be the same object type 0330 * (Both are Integer, String, or Buffer), and we can now perform 0331 * the concatenation. 0332 * 0333 * There are three cases to handle, as per the ACPI spec: 0334 * 0335 * 1) Two Integers concatenated to produce a new Buffer 0336 * 2) Two Strings concatenated to produce a new String 0337 * 3) Two Buffers concatenated to produce a new Buffer 0338 */ 0339 switch (Operand0Type) 0340 { 0341 case ACPI_TYPE_INTEGER: 0342 0343 /* Result of two Integers is a Buffer */ 0344 /* Need enough buffer space for two integers */ 0345 0346 ReturnDesc = AcpiUtCreateBufferObject ( 0347 (ACPI_SIZE) ACPI_MUL_2 (AcpiGbl_IntegerByteWidth)); 0348 if (!ReturnDesc) 0349 { 0350 Status = AE_NO_MEMORY; 0351 goto Cleanup; 0352 } 0353 0354 Buffer = (char *) ReturnDesc->Buffer.Pointer; 0355 0356 /* Copy the first integer, LSB first */ 0357 0358 memcpy (Buffer, &Operand0->Integer.Value, 0359 AcpiGbl_IntegerByteWidth); 0360 0361 /* Copy the second integer (LSB first) after the first */ 0362 0363 memcpy (Buffer + AcpiGbl_IntegerByteWidth, 0364 &LocalOperand1->Integer.Value, AcpiGbl_IntegerByteWidth); 0365 break; 0366 0367 case ACPI_TYPE_STRING: 0368 0369 /* Result of two Strings is a String */ 0370 0371 ReturnDesc = AcpiUtCreateStringObject ( 0372 ((ACPI_SIZE) LocalOperand0->String.Length + 0373 LocalOperand1->String.Length)); 0374 if (!ReturnDesc) 0375 { 0376 Status = AE_NO_MEMORY; 0377 goto Cleanup; 0378 } 0379 0380 Buffer = ReturnDesc->String.Pointer; 0381 0382 /* Concatenate the strings */ 0383 0384 strcpy (Buffer, LocalOperand0->String.Pointer); 0385 strcat (Buffer, LocalOperand1->String.Pointer); 0386 break; 0387 0388 case ACPI_TYPE_BUFFER: 0389 0390 /* Result of two Buffers is a Buffer */ 0391 0392 ReturnDesc = AcpiUtCreateBufferObject ( 0393 ((ACPI_SIZE) Operand0->Buffer.Length + 0394 LocalOperand1->Buffer.Length)); 0395 if (!ReturnDesc) 0396 { 0397 Status = AE_NO_MEMORY; 0398 goto Cleanup; 0399 } 0400 0401 Buffer = (char *) ReturnDesc->Buffer.Pointer; 0402 0403 /* Concatenate the buffers */ 0404 0405 memcpy (Buffer, Operand0->Buffer.Pointer, 0406 Operand0->Buffer.Length); 0407 memcpy (Buffer + Operand0->Buffer.Length, 0408 LocalOperand1->Buffer.Pointer, 0409 LocalOperand1->Buffer.Length); 0410 break; 0411 0412 default: 0413 0414 /* Invalid object type, should not happen here */ 0415 0416 ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X", 0417 Operand0->Common.Type)); 0418 Status = AE_AML_INTERNAL; 0419 goto Cleanup; 0420 } 0421 0422 *ActualReturnDesc = ReturnDesc; 0423 0424 Cleanup: 0425 if (LocalOperand0 != Operand0) 0426 { 0427 AcpiUtRemoveReference (LocalOperand0); 0428 } 0429 0430 if (LocalOperand1 != Operand1) 0431 { 0432 AcpiUtRemoveReference (LocalOperand1); 0433 } 0434 0435 return_ACPI_STATUS (Status); 0436 } 0437 0438 0439 /******************************************************************************* 0440 * 0441 * FUNCTION: AcpiExConvertToObjectTypeString 0442 * 0443 * PARAMETERS: ObjDesc - Object to be converted 0444 * ReturnDesc - Where to place the return object 0445 * 0446 * RETURN: Status 0447 * 0448 * DESCRIPTION: Convert an object of arbitrary type to a string object that 0449 * contains the namestring for the object. Used for the 0450 * concatenate operator. 0451 * 0452 ******************************************************************************/ 0453 0454 static ACPI_STATUS 0455 AcpiExConvertToObjectTypeString ( 0456 ACPI_OPERAND_OBJECT *ObjDesc, 0457 ACPI_OPERAND_OBJECT **ResultDesc) 0458 { 0459 ACPI_OPERAND_OBJECT *ReturnDesc; 0460 const char *TypeString; 0461 0462 0463 TypeString = AcpiUtGetTypeName (ObjDesc->Common.Type); 0464 0465 ReturnDesc = AcpiUtCreateStringObject ( 0466 ((ACPI_SIZE) strlen (TypeString) + 9)); /* 9 For "[ Object]" */ 0467 if (!ReturnDesc) 0468 { 0469 return (AE_NO_MEMORY); 0470 } 0471 0472 strcpy (ReturnDesc->String.Pointer, "["); 0473 strcat (ReturnDesc->String.Pointer, TypeString); 0474 strcat (ReturnDesc->String.Pointer, " Object]"); 0475 0476 *ResultDesc = ReturnDesc; 0477 return (AE_OK); 0478 } 0479 0480 0481 /******************************************************************************* 0482 * 0483 * FUNCTION: AcpiExConcatTemplate 0484 * 0485 * PARAMETERS: Operand0 - First source object 0486 * Operand1 - Second source object 0487 * ActualReturnDesc - Where to place the return object 0488 * WalkState - Current walk state 0489 * 0490 * RETURN: Status 0491 * 0492 * DESCRIPTION: Concatenate two resource templates 0493 * 0494 ******************************************************************************/ 0495 0496 ACPI_STATUS 0497 AcpiExConcatTemplate ( 0498 ACPI_OPERAND_OBJECT *Operand0, 0499 ACPI_OPERAND_OBJECT *Operand1, 0500 ACPI_OPERAND_OBJECT **ActualReturnDesc, 0501 ACPI_WALK_STATE *WalkState) 0502 { 0503 ACPI_STATUS Status; 0504 ACPI_OPERAND_OBJECT *ReturnDesc; 0505 UINT8 *NewBuf; 0506 UINT8 *EndTag; 0507 ACPI_SIZE Length0; 0508 ACPI_SIZE Length1; 0509 ACPI_SIZE NewLength; 0510 0511 0512 ACPI_FUNCTION_TRACE (ExConcatTemplate); 0513 0514 0515 /* 0516 * Find the EndTag descriptor in each resource template. 0517 * Note1: returned pointers point TO the EndTag, not past it. 0518 * Note2: zero-length buffers are allowed; treated like one EndTag 0519 */ 0520 0521 /* Get the length of the first resource template */ 0522 0523 Status = AcpiUtGetResourceEndTag (Operand0, &EndTag); 0524 if (ACPI_FAILURE (Status)) 0525 { 0526 return_ACPI_STATUS (Status); 0527 } 0528 0529 Length0 = ACPI_PTR_DIFF (EndTag, Operand0->Buffer.Pointer); 0530 0531 /* Get the length of the second resource template */ 0532 0533 Status = AcpiUtGetResourceEndTag (Operand1, &EndTag); 0534 if (ACPI_FAILURE (Status)) 0535 { 0536 return_ACPI_STATUS (Status); 0537 } 0538 0539 Length1 = ACPI_PTR_DIFF (EndTag, Operand1->Buffer.Pointer); 0540 0541 /* Combine both lengths, minimum size will be 2 for EndTag */ 0542 0543 NewLength = Length0 + Length1 + sizeof (AML_RESOURCE_END_TAG); 0544 0545 /* Create a new buffer object for the result (with one EndTag) */ 0546 0547 ReturnDesc = AcpiUtCreateBufferObject (NewLength); 0548 if (!ReturnDesc) 0549 { 0550 return_ACPI_STATUS (AE_NO_MEMORY); 0551 } 0552 0553 /* 0554 * Copy the templates to the new buffer, 0 first, then 1 follows. One 0555 * EndTag descriptor is copied from Operand1. 0556 */ 0557 NewBuf = ReturnDesc->Buffer.Pointer; 0558 memcpy (NewBuf, Operand0->Buffer.Pointer, Length0); 0559 memcpy (NewBuf + Length0, Operand1->Buffer.Pointer, Length1); 0560 0561 /* Insert EndTag and set the checksum to zero, means "ignore checksum" */ 0562 0563 NewBuf[NewLength - 1] = 0; 0564 NewBuf[NewLength - 2] = ACPI_RESOURCE_NAME_END_TAG | 1; 0565 0566 /* Return the completed resource template */ 0567 0568 *ActualReturnDesc = ReturnDesc; 0569 return_ACPI_STATUS (AE_OK); 0570 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |