Home | History | Annotate | Line # | Download | only in executer
exconcat.c revision 1.1.1.4.2.2
      1  1.1.1.4.2.2  jdolecek /******************************************************************************
      2  1.1.1.4.2.2  jdolecek  *
      3  1.1.1.4.2.2  jdolecek  * Module Name: exconcat - Concatenate-type AML operators
      4  1.1.1.4.2.2  jdolecek  *
      5  1.1.1.4.2.2  jdolecek  *****************************************************************************/
      6  1.1.1.4.2.2  jdolecek 
      7  1.1.1.4.2.2  jdolecek /*
      8  1.1.1.4.2.2  jdolecek  * Copyright (C) 2000 - 2017, Intel Corp.
      9  1.1.1.4.2.2  jdolecek  * All rights reserved.
     10  1.1.1.4.2.2  jdolecek  *
     11  1.1.1.4.2.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.4.2.2  jdolecek  * modification, are permitted provided that the following conditions
     13  1.1.1.4.2.2  jdolecek  * are met:
     14  1.1.1.4.2.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.4.2.2  jdolecek  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.4.2.2  jdolecek  *    without modification.
     17  1.1.1.4.2.2  jdolecek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.4.2.2  jdolecek  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.4.2.2  jdolecek  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.4.2.2  jdolecek  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.4.2.2  jdolecek  *    binary redistribution.
     22  1.1.1.4.2.2  jdolecek  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.4.2.2  jdolecek  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.4.2.2  jdolecek  *    from this software without specific prior written permission.
     25  1.1.1.4.2.2  jdolecek  *
     26  1.1.1.4.2.2  jdolecek  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.4.2.2  jdolecek  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.4.2.2  jdolecek  * Software Foundation.
     29  1.1.1.4.2.2  jdolecek  *
     30  1.1.1.4.2.2  jdolecek  * NO WARRANTY
     31  1.1.1.4.2.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.4.2.2  jdolecek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.4.2.2  jdolecek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.4.2.2  jdolecek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.4.2.2  jdolecek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.4.2.2  jdolecek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.4.2.2  jdolecek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.4.2.2  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.4.2.2  jdolecek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.4.2.2  jdolecek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.4.2.2  jdolecek  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.4.2.2  jdolecek  */
     43  1.1.1.4.2.2  jdolecek 
     44  1.1.1.4.2.2  jdolecek #include "acpi.h"
     45  1.1.1.4.2.2  jdolecek #include "accommon.h"
     46  1.1.1.4.2.2  jdolecek #include "acinterp.h"
     47  1.1.1.4.2.2  jdolecek #include "amlresrc.h"
     48  1.1.1.4.2.2  jdolecek 
     49  1.1.1.4.2.2  jdolecek 
     50  1.1.1.4.2.2  jdolecek #define _COMPONENT          ACPI_EXECUTER
     51  1.1.1.4.2.2  jdolecek         ACPI_MODULE_NAME    ("exconcat")
     52  1.1.1.4.2.2  jdolecek 
     53  1.1.1.4.2.2  jdolecek /* Local Prototypes */
     54  1.1.1.4.2.2  jdolecek 
     55  1.1.1.4.2.2  jdolecek static ACPI_STATUS
     56  1.1.1.4.2.2  jdolecek AcpiExConvertToObjectTypeString (
     57  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     *ObjDesc,
     58  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     **ResultDesc);
     59  1.1.1.4.2.2  jdolecek 
     60  1.1.1.4.2.2  jdolecek 
     61  1.1.1.4.2.2  jdolecek /*******************************************************************************
     62  1.1.1.4.2.2  jdolecek  *
     63  1.1.1.4.2.2  jdolecek  * FUNCTION:    AcpiExDoConcatenate
     64  1.1.1.4.2.2  jdolecek  *
     65  1.1.1.4.2.2  jdolecek  * PARAMETERS:  Operand0            - First source object
     66  1.1.1.4.2.2  jdolecek  *              Operand1            - Second source object
     67  1.1.1.4.2.2  jdolecek  *              ActualReturnDesc    - Where to place the return object
     68  1.1.1.4.2.2  jdolecek  *              WalkState           - Current walk state
     69  1.1.1.4.2.2  jdolecek  *
     70  1.1.1.4.2.2  jdolecek  * RETURN:      Status
     71  1.1.1.4.2.2  jdolecek  *
     72  1.1.1.4.2.2  jdolecek  * DESCRIPTION: Concatenate two objects with the ACPI-defined conversion
     73  1.1.1.4.2.2  jdolecek  *              rules as necessary.
     74  1.1.1.4.2.2  jdolecek  * NOTE:
     75  1.1.1.4.2.2  jdolecek  * Per the ACPI spec (up to 6.1), Concatenate only supports Integer,
     76  1.1.1.4.2.2  jdolecek  * String, and Buffer objects. However, we support all objects here
     77  1.1.1.4.2.2  jdolecek  * as an extension. This improves the usefulness of both Concatenate
     78  1.1.1.4.2.2  jdolecek  * and the Printf/Fprintf macros. The extension returns a string
     79  1.1.1.4.2.2  jdolecek  * describing the object type for the other objects.
     80  1.1.1.4.2.2  jdolecek  * 02/2016.
     81  1.1.1.4.2.2  jdolecek  *
     82  1.1.1.4.2.2  jdolecek  ******************************************************************************/
     83  1.1.1.4.2.2  jdolecek 
     84  1.1.1.4.2.2  jdolecek ACPI_STATUS
     85  1.1.1.4.2.2  jdolecek AcpiExDoConcatenate (
     86  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     *Operand0,
     87  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     *Operand1,
     88  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     **ActualReturnDesc,
     89  1.1.1.4.2.2  jdolecek     ACPI_WALK_STATE         *WalkState)
     90  1.1.1.4.2.2  jdolecek {
     91  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     *LocalOperand0 = Operand0;
     92  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     *LocalOperand1 = Operand1;
     93  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     *TempOperand1 = NULL;
     94  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     *ReturnDesc;
     95  1.1.1.4.2.2  jdolecek     char                    *Buffer;
     96  1.1.1.4.2.2  jdolecek     ACPI_OBJECT_TYPE        Operand0Type;
     97  1.1.1.4.2.2  jdolecek     ACPI_OBJECT_TYPE        Operand1Type;
     98  1.1.1.4.2.2  jdolecek     ACPI_STATUS             Status;
     99  1.1.1.4.2.2  jdolecek 
    100  1.1.1.4.2.2  jdolecek 
    101  1.1.1.4.2.2  jdolecek     ACPI_FUNCTION_TRACE (ExDoConcatenate);
    102  1.1.1.4.2.2  jdolecek 
    103  1.1.1.4.2.2  jdolecek 
    104  1.1.1.4.2.2  jdolecek     /* Operand 0 preprocessing */
    105  1.1.1.4.2.2  jdolecek 
    106  1.1.1.4.2.2  jdolecek     switch (Operand0->Common.Type)
    107  1.1.1.4.2.2  jdolecek     {
    108  1.1.1.4.2.2  jdolecek     case ACPI_TYPE_INTEGER:
    109  1.1.1.4.2.2  jdolecek     case ACPI_TYPE_STRING:
    110  1.1.1.4.2.2  jdolecek     case ACPI_TYPE_BUFFER:
    111  1.1.1.4.2.2  jdolecek 
    112  1.1.1.4.2.2  jdolecek         Operand0Type = Operand0->Common.Type;
    113  1.1.1.4.2.2  jdolecek         break;
    114  1.1.1.4.2.2  jdolecek 
    115  1.1.1.4.2.2  jdolecek     default:
    116  1.1.1.4.2.2  jdolecek 
    117  1.1.1.4.2.2  jdolecek         /* For all other types, get the "object type" string */
    118  1.1.1.4.2.2  jdolecek 
    119  1.1.1.4.2.2  jdolecek         Status = AcpiExConvertToObjectTypeString (
    120  1.1.1.4.2.2  jdolecek             Operand0, &LocalOperand0);
    121  1.1.1.4.2.2  jdolecek         if (ACPI_FAILURE (Status))
    122  1.1.1.4.2.2  jdolecek         {
    123  1.1.1.4.2.2  jdolecek             goto Cleanup;
    124  1.1.1.4.2.2  jdolecek         }
    125  1.1.1.4.2.2  jdolecek 
    126  1.1.1.4.2.2  jdolecek         Operand0Type = ACPI_TYPE_STRING;
    127  1.1.1.4.2.2  jdolecek         break;
    128  1.1.1.4.2.2  jdolecek     }
    129  1.1.1.4.2.2  jdolecek 
    130  1.1.1.4.2.2  jdolecek     /* Operand 1 preprocessing */
    131  1.1.1.4.2.2  jdolecek 
    132  1.1.1.4.2.2  jdolecek     switch (Operand1->Common.Type)
    133  1.1.1.4.2.2  jdolecek     {
    134  1.1.1.4.2.2  jdolecek     case ACPI_TYPE_INTEGER:
    135  1.1.1.4.2.2  jdolecek     case ACPI_TYPE_STRING:
    136  1.1.1.4.2.2  jdolecek     case ACPI_TYPE_BUFFER:
    137  1.1.1.4.2.2  jdolecek 
    138  1.1.1.4.2.2  jdolecek         Operand1Type = Operand1->Common.Type;
    139  1.1.1.4.2.2  jdolecek         break;
    140  1.1.1.4.2.2  jdolecek 
    141  1.1.1.4.2.2  jdolecek     default:
    142  1.1.1.4.2.2  jdolecek 
    143  1.1.1.4.2.2  jdolecek         /* For all other types, get the "object type" string */
    144  1.1.1.4.2.2  jdolecek 
    145  1.1.1.4.2.2  jdolecek         Status = AcpiExConvertToObjectTypeString (
    146  1.1.1.4.2.2  jdolecek             Operand1, &LocalOperand1);
    147  1.1.1.4.2.2  jdolecek         if (ACPI_FAILURE (Status))
    148  1.1.1.4.2.2  jdolecek         {
    149  1.1.1.4.2.2  jdolecek             goto Cleanup;
    150  1.1.1.4.2.2  jdolecek         }
    151  1.1.1.4.2.2  jdolecek 
    152  1.1.1.4.2.2  jdolecek         Operand1Type = ACPI_TYPE_STRING;
    153  1.1.1.4.2.2  jdolecek         break;
    154  1.1.1.4.2.2  jdolecek     }
    155  1.1.1.4.2.2  jdolecek 
    156  1.1.1.4.2.2  jdolecek     /*
    157  1.1.1.4.2.2  jdolecek      * Convert the second operand if necessary. The first operand (0)
    158  1.1.1.4.2.2  jdolecek      * determines the type of the second operand (1) (See the Data Types
    159  1.1.1.4.2.2  jdolecek      * section of the ACPI specification). Both object types are
    160  1.1.1.4.2.2  jdolecek      * guaranteed to be either Integer/String/Buffer by the operand
    161  1.1.1.4.2.2  jdolecek      * resolution mechanism.
    162  1.1.1.4.2.2  jdolecek      */
    163  1.1.1.4.2.2  jdolecek     switch (Operand0Type)
    164  1.1.1.4.2.2  jdolecek     {
    165  1.1.1.4.2.2  jdolecek     case ACPI_TYPE_INTEGER:
    166  1.1.1.4.2.2  jdolecek 
    167  1.1.1.4.2.2  jdolecek         Status = AcpiExConvertToInteger (LocalOperand1, &TempOperand1,
    168  1.1.1.4.2.2  jdolecek             ACPI_IMPLICIT_CONVERSION);
    169  1.1.1.4.2.2  jdolecek         break;
    170  1.1.1.4.2.2  jdolecek 
    171  1.1.1.4.2.2  jdolecek     case ACPI_TYPE_BUFFER:
    172  1.1.1.4.2.2  jdolecek 
    173  1.1.1.4.2.2  jdolecek         Status = AcpiExConvertToBuffer (LocalOperand1, &TempOperand1);
    174  1.1.1.4.2.2  jdolecek         break;
    175  1.1.1.4.2.2  jdolecek 
    176  1.1.1.4.2.2  jdolecek     case ACPI_TYPE_STRING:
    177  1.1.1.4.2.2  jdolecek 
    178  1.1.1.4.2.2  jdolecek         switch (Operand1Type)
    179  1.1.1.4.2.2  jdolecek         {
    180  1.1.1.4.2.2  jdolecek         case ACPI_TYPE_INTEGER:
    181  1.1.1.4.2.2  jdolecek         case ACPI_TYPE_STRING:
    182  1.1.1.4.2.2  jdolecek         case ACPI_TYPE_BUFFER:
    183  1.1.1.4.2.2  jdolecek 
    184  1.1.1.4.2.2  jdolecek             /* Other types have already been converted to string */
    185  1.1.1.4.2.2  jdolecek 
    186  1.1.1.4.2.2  jdolecek             Status = AcpiExConvertToString (
    187  1.1.1.4.2.2  jdolecek                 LocalOperand1, &TempOperand1, ACPI_IMPLICIT_CONVERT_HEX);
    188  1.1.1.4.2.2  jdolecek             break;
    189  1.1.1.4.2.2  jdolecek 
    190  1.1.1.4.2.2  jdolecek         default:
    191  1.1.1.4.2.2  jdolecek 
    192  1.1.1.4.2.2  jdolecek             Status = AE_OK;
    193  1.1.1.4.2.2  jdolecek             break;
    194  1.1.1.4.2.2  jdolecek         }
    195  1.1.1.4.2.2  jdolecek         break;
    196  1.1.1.4.2.2  jdolecek 
    197  1.1.1.4.2.2  jdolecek     default:
    198  1.1.1.4.2.2  jdolecek 
    199  1.1.1.4.2.2  jdolecek         ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
    200  1.1.1.4.2.2  jdolecek             Operand0->Common.Type));
    201  1.1.1.4.2.2  jdolecek         Status = AE_AML_INTERNAL;
    202  1.1.1.4.2.2  jdolecek     }
    203  1.1.1.4.2.2  jdolecek 
    204  1.1.1.4.2.2  jdolecek     if (ACPI_FAILURE (Status))
    205  1.1.1.4.2.2  jdolecek     {
    206  1.1.1.4.2.2  jdolecek         goto Cleanup;
    207  1.1.1.4.2.2  jdolecek     }
    208  1.1.1.4.2.2  jdolecek 
    209  1.1.1.4.2.2  jdolecek     /* Take care with any newly created operand objects */
    210  1.1.1.4.2.2  jdolecek 
    211  1.1.1.4.2.2  jdolecek     if ((LocalOperand1 != Operand1) &&
    212  1.1.1.4.2.2  jdolecek         (LocalOperand1 != TempOperand1))
    213  1.1.1.4.2.2  jdolecek     {
    214  1.1.1.4.2.2  jdolecek         AcpiUtRemoveReference (LocalOperand1);
    215  1.1.1.4.2.2  jdolecek     }
    216  1.1.1.4.2.2  jdolecek 
    217  1.1.1.4.2.2  jdolecek     LocalOperand1 = TempOperand1;
    218  1.1.1.4.2.2  jdolecek 
    219  1.1.1.4.2.2  jdolecek     /*
    220  1.1.1.4.2.2  jdolecek      * Both operands are now known to be the same object type
    221  1.1.1.4.2.2  jdolecek      * (Both are Integer, String, or Buffer), and we can now perform
    222  1.1.1.4.2.2  jdolecek      * the concatenation.
    223  1.1.1.4.2.2  jdolecek      *
    224  1.1.1.4.2.2  jdolecek      * There are three cases to handle, as per the ACPI spec:
    225  1.1.1.4.2.2  jdolecek      *
    226  1.1.1.4.2.2  jdolecek      * 1) Two Integers concatenated to produce a new Buffer
    227  1.1.1.4.2.2  jdolecek      * 2) Two Strings concatenated to produce a new String
    228  1.1.1.4.2.2  jdolecek      * 3) Two Buffers concatenated to produce a new Buffer
    229  1.1.1.4.2.2  jdolecek      */
    230  1.1.1.4.2.2  jdolecek     switch (Operand0Type)
    231  1.1.1.4.2.2  jdolecek     {
    232  1.1.1.4.2.2  jdolecek     case ACPI_TYPE_INTEGER:
    233  1.1.1.4.2.2  jdolecek 
    234  1.1.1.4.2.2  jdolecek         /* Result of two Integers is a Buffer */
    235  1.1.1.4.2.2  jdolecek         /* Need enough buffer space for two integers */
    236  1.1.1.4.2.2  jdolecek 
    237  1.1.1.4.2.2  jdolecek         ReturnDesc = AcpiUtCreateBufferObject (
    238  1.1.1.4.2.2  jdolecek             (ACPI_SIZE) ACPI_MUL_2 (AcpiGbl_IntegerByteWidth));
    239  1.1.1.4.2.2  jdolecek         if (!ReturnDesc)
    240  1.1.1.4.2.2  jdolecek         {
    241  1.1.1.4.2.2  jdolecek             Status = AE_NO_MEMORY;
    242  1.1.1.4.2.2  jdolecek             goto Cleanup;
    243  1.1.1.4.2.2  jdolecek         }
    244  1.1.1.4.2.2  jdolecek 
    245  1.1.1.4.2.2  jdolecek         Buffer = (char *) ReturnDesc->Buffer.Pointer;
    246  1.1.1.4.2.2  jdolecek 
    247  1.1.1.4.2.2  jdolecek         /* Copy the first integer, LSB first */
    248  1.1.1.4.2.2  jdolecek 
    249  1.1.1.4.2.2  jdolecek         memcpy (Buffer, &Operand0->Integer.Value,
    250  1.1.1.4.2.2  jdolecek             AcpiGbl_IntegerByteWidth);
    251  1.1.1.4.2.2  jdolecek 
    252  1.1.1.4.2.2  jdolecek         /* Copy the second integer (LSB first) after the first */
    253  1.1.1.4.2.2  jdolecek 
    254  1.1.1.4.2.2  jdolecek         memcpy (Buffer + AcpiGbl_IntegerByteWidth,
    255  1.1.1.4.2.2  jdolecek             &LocalOperand1->Integer.Value, AcpiGbl_IntegerByteWidth);
    256  1.1.1.4.2.2  jdolecek         break;
    257  1.1.1.4.2.2  jdolecek 
    258  1.1.1.4.2.2  jdolecek     case ACPI_TYPE_STRING:
    259  1.1.1.4.2.2  jdolecek 
    260  1.1.1.4.2.2  jdolecek         /* Result of two Strings is a String */
    261  1.1.1.4.2.2  jdolecek 
    262  1.1.1.4.2.2  jdolecek         ReturnDesc = AcpiUtCreateStringObject (
    263  1.1.1.4.2.2  jdolecek             ((ACPI_SIZE) LocalOperand0->String.Length +
    264  1.1.1.4.2.2  jdolecek             LocalOperand1->String.Length));
    265  1.1.1.4.2.2  jdolecek         if (!ReturnDesc)
    266  1.1.1.4.2.2  jdolecek         {
    267  1.1.1.4.2.2  jdolecek             Status = AE_NO_MEMORY;
    268  1.1.1.4.2.2  jdolecek             goto Cleanup;
    269  1.1.1.4.2.2  jdolecek         }
    270  1.1.1.4.2.2  jdolecek 
    271  1.1.1.4.2.2  jdolecek         Buffer = ReturnDesc->String.Pointer;
    272  1.1.1.4.2.2  jdolecek 
    273  1.1.1.4.2.2  jdolecek         /* Concatenate the strings */
    274  1.1.1.4.2.2  jdolecek 
    275  1.1.1.4.2.2  jdolecek         strcpy (Buffer, LocalOperand0->String.Pointer);
    276  1.1.1.4.2.2  jdolecek         strcat (Buffer, LocalOperand1->String.Pointer);
    277  1.1.1.4.2.2  jdolecek         break;
    278  1.1.1.4.2.2  jdolecek 
    279  1.1.1.4.2.2  jdolecek     case ACPI_TYPE_BUFFER:
    280  1.1.1.4.2.2  jdolecek 
    281  1.1.1.4.2.2  jdolecek         /* Result of two Buffers is a Buffer */
    282  1.1.1.4.2.2  jdolecek 
    283  1.1.1.4.2.2  jdolecek         ReturnDesc = AcpiUtCreateBufferObject (
    284  1.1.1.4.2.2  jdolecek             ((ACPI_SIZE) Operand0->Buffer.Length +
    285  1.1.1.4.2.2  jdolecek             LocalOperand1->Buffer.Length));
    286  1.1.1.4.2.2  jdolecek         if (!ReturnDesc)
    287  1.1.1.4.2.2  jdolecek         {
    288  1.1.1.4.2.2  jdolecek             Status = AE_NO_MEMORY;
    289  1.1.1.4.2.2  jdolecek             goto Cleanup;
    290  1.1.1.4.2.2  jdolecek         }
    291  1.1.1.4.2.2  jdolecek 
    292  1.1.1.4.2.2  jdolecek         Buffer = (char *) ReturnDesc->Buffer.Pointer;
    293  1.1.1.4.2.2  jdolecek 
    294  1.1.1.4.2.2  jdolecek         /* Concatenate the buffers */
    295  1.1.1.4.2.2  jdolecek 
    296  1.1.1.4.2.2  jdolecek         memcpy (Buffer, Operand0->Buffer.Pointer,
    297  1.1.1.4.2.2  jdolecek             Operand0->Buffer.Length);
    298  1.1.1.4.2.2  jdolecek         memcpy (Buffer + Operand0->Buffer.Length,
    299  1.1.1.4.2.2  jdolecek             LocalOperand1->Buffer.Pointer,
    300  1.1.1.4.2.2  jdolecek             LocalOperand1->Buffer.Length);
    301  1.1.1.4.2.2  jdolecek         break;
    302  1.1.1.4.2.2  jdolecek 
    303  1.1.1.4.2.2  jdolecek     default:
    304  1.1.1.4.2.2  jdolecek 
    305  1.1.1.4.2.2  jdolecek         /* Invalid object type, should not happen here */
    306  1.1.1.4.2.2  jdolecek 
    307  1.1.1.4.2.2  jdolecek         ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
    308  1.1.1.4.2.2  jdolecek             Operand0->Common.Type));
    309  1.1.1.4.2.2  jdolecek         Status = AE_AML_INTERNAL;
    310  1.1.1.4.2.2  jdolecek         goto Cleanup;
    311  1.1.1.4.2.2  jdolecek     }
    312  1.1.1.4.2.2  jdolecek 
    313  1.1.1.4.2.2  jdolecek     *ActualReturnDesc = ReturnDesc;
    314  1.1.1.4.2.2  jdolecek 
    315  1.1.1.4.2.2  jdolecek Cleanup:
    316  1.1.1.4.2.2  jdolecek     if (LocalOperand0 != Operand0)
    317  1.1.1.4.2.2  jdolecek     {
    318  1.1.1.4.2.2  jdolecek         AcpiUtRemoveReference (LocalOperand0);
    319  1.1.1.4.2.2  jdolecek     }
    320  1.1.1.4.2.2  jdolecek 
    321  1.1.1.4.2.2  jdolecek     if (LocalOperand1 != Operand1)
    322  1.1.1.4.2.2  jdolecek     {
    323  1.1.1.4.2.2  jdolecek         AcpiUtRemoveReference (LocalOperand1);
    324  1.1.1.4.2.2  jdolecek     }
    325  1.1.1.4.2.2  jdolecek 
    326  1.1.1.4.2.2  jdolecek     return_ACPI_STATUS (Status);
    327  1.1.1.4.2.2  jdolecek }
    328  1.1.1.4.2.2  jdolecek 
    329  1.1.1.4.2.2  jdolecek 
    330  1.1.1.4.2.2  jdolecek /*******************************************************************************
    331  1.1.1.4.2.2  jdolecek  *
    332  1.1.1.4.2.2  jdolecek  * FUNCTION:    AcpiExConvertToObjectTypeString
    333  1.1.1.4.2.2  jdolecek  *
    334  1.1.1.4.2.2  jdolecek  * PARAMETERS:  ObjDesc             - Object to be converted
    335  1.1.1.4.2.2  jdolecek  *              ReturnDesc          - Where to place the return object
    336  1.1.1.4.2.2  jdolecek  *
    337  1.1.1.4.2.2  jdolecek  * RETURN:      Status
    338  1.1.1.4.2.2  jdolecek  *
    339  1.1.1.4.2.2  jdolecek  * DESCRIPTION: Convert an object of arbitrary type to a string object that
    340  1.1.1.4.2.2  jdolecek  *              contains the namestring for the object. Used for the
    341  1.1.1.4.2.2  jdolecek  *              concatenate operator.
    342  1.1.1.4.2.2  jdolecek  *
    343  1.1.1.4.2.2  jdolecek  ******************************************************************************/
    344  1.1.1.4.2.2  jdolecek 
    345  1.1.1.4.2.2  jdolecek static ACPI_STATUS
    346  1.1.1.4.2.2  jdolecek AcpiExConvertToObjectTypeString (
    347  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     *ObjDesc,
    348  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     **ResultDesc)
    349  1.1.1.4.2.2  jdolecek {
    350  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     *ReturnDesc;
    351  1.1.1.4.2.2  jdolecek     const char              *TypeString;
    352  1.1.1.4.2.2  jdolecek 
    353  1.1.1.4.2.2  jdolecek 
    354  1.1.1.4.2.2  jdolecek     TypeString = AcpiUtGetTypeName (ObjDesc->Common.Type);
    355  1.1.1.4.2.2  jdolecek 
    356  1.1.1.4.2.2  jdolecek     ReturnDesc = AcpiUtCreateStringObject (
    357  1.1.1.4.2.2  jdolecek         ((ACPI_SIZE) strlen (TypeString) + 9)); /* 9 For "[ Object]" */
    358  1.1.1.4.2.2  jdolecek     if (!ReturnDesc)
    359  1.1.1.4.2.2  jdolecek     {
    360  1.1.1.4.2.2  jdolecek         return (AE_NO_MEMORY);
    361  1.1.1.4.2.2  jdolecek     }
    362  1.1.1.4.2.2  jdolecek 
    363  1.1.1.4.2.2  jdolecek     strcpy (ReturnDesc->String.Pointer, "[");
    364  1.1.1.4.2.2  jdolecek     strcat (ReturnDesc->String.Pointer, TypeString);
    365  1.1.1.4.2.2  jdolecek     strcat (ReturnDesc->String.Pointer, " Object]");
    366  1.1.1.4.2.2  jdolecek 
    367  1.1.1.4.2.2  jdolecek     *ResultDesc = ReturnDesc;
    368  1.1.1.4.2.2  jdolecek     return (AE_OK);
    369  1.1.1.4.2.2  jdolecek }
    370  1.1.1.4.2.2  jdolecek 
    371  1.1.1.4.2.2  jdolecek 
    372  1.1.1.4.2.2  jdolecek /*******************************************************************************
    373  1.1.1.4.2.2  jdolecek  *
    374  1.1.1.4.2.2  jdolecek  * FUNCTION:    AcpiExConcatTemplate
    375  1.1.1.4.2.2  jdolecek  *
    376  1.1.1.4.2.2  jdolecek  * PARAMETERS:  Operand0            - First source object
    377  1.1.1.4.2.2  jdolecek  *              Operand1            - Second source object
    378  1.1.1.4.2.2  jdolecek  *              ActualReturnDesc    - Where to place the return object
    379  1.1.1.4.2.2  jdolecek  *              WalkState           - Current walk state
    380  1.1.1.4.2.2  jdolecek  *
    381  1.1.1.4.2.2  jdolecek  * RETURN:      Status
    382  1.1.1.4.2.2  jdolecek  *
    383  1.1.1.4.2.2  jdolecek  * DESCRIPTION: Concatenate two resource templates
    384  1.1.1.4.2.2  jdolecek  *
    385  1.1.1.4.2.2  jdolecek  ******************************************************************************/
    386  1.1.1.4.2.2  jdolecek 
    387  1.1.1.4.2.2  jdolecek ACPI_STATUS
    388  1.1.1.4.2.2  jdolecek AcpiExConcatTemplate (
    389  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     *Operand0,
    390  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     *Operand1,
    391  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     **ActualReturnDesc,
    392  1.1.1.4.2.2  jdolecek     ACPI_WALK_STATE         *WalkState)
    393  1.1.1.4.2.2  jdolecek {
    394  1.1.1.4.2.2  jdolecek     ACPI_STATUS             Status;
    395  1.1.1.4.2.2  jdolecek     ACPI_OPERAND_OBJECT     *ReturnDesc;
    396  1.1.1.4.2.2  jdolecek     UINT8                   *NewBuf;
    397  1.1.1.4.2.2  jdolecek     UINT8                   *EndTag;
    398  1.1.1.4.2.2  jdolecek     ACPI_SIZE               Length0;
    399  1.1.1.4.2.2  jdolecek     ACPI_SIZE               Length1;
    400  1.1.1.4.2.2  jdolecek     ACPI_SIZE               NewLength;
    401  1.1.1.4.2.2  jdolecek 
    402  1.1.1.4.2.2  jdolecek 
    403  1.1.1.4.2.2  jdolecek     ACPI_FUNCTION_TRACE (ExConcatTemplate);
    404  1.1.1.4.2.2  jdolecek 
    405  1.1.1.4.2.2  jdolecek 
    406  1.1.1.4.2.2  jdolecek     /*
    407  1.1.1.4.2.2  jdolecek      * Find the EndTag descriptor in each resource template.
    408  1.1.1.4.2.2  jdolecek      * Note1: returned pointers point TO the EndTag, not past it.
    409  1.1.1.4.2.2  jdolecek      * Note2: zero-length buffers are allowed; treated like one EndTag
    410  1.1.1.4.2.2  jdolecek      */
    411  1.1.1.4.2.2  jdolecek 
    412  1.1.1.4.2.2  jdolecek     /* Get the length of the first resource template */
    413  1.1.1.4.2.2  jdolecek 
    414  1.1.1.4.2.2  jdolecek     Status = AcpiUtGetResourceEndTag (Operand0, &EndTag);
    415  1.1.1.4.2.2  jdolecek     if (ACPI_FAILURE (Status))
    416  1.1.1.4.2.2  jdolecek     {
    417  1.1.1.4.2.2  jdolecek         return_ACPI_STATUS (Status);
    418  1.1.1.4.2.2  jdolecek     }
    419  1.1.1.4.2.2  jdolecek 
    420  1.1.1.4.2.2  jdolecek     Length0 = ACPI_PTR_DIFF (EndTag, Operand0->Buffer.Pointer);
    421  1.1.1.4.2.2  jdolecek 
    422  1.1.1.4.2.2  jdolecek     /* Get the length of the second resource template */
    423  1.1.1.4.2.2  jdolecek 
    424  1.1.1.4.2.2  jdolecek     Status = AcpiUtGetResourceEndTag (Operand1, &EndTag);
    425  1.1.1.4.2.2  jdolecek     if (ACPI_FAILURE (Status))
    426  1.1.1.4.2.2  jdolecek     {
    427  1.1.1.4.2.2  jdolecek         return_ACPI_STATUS (Status);
    428  1.1.1.4.2.2  jdolecek     }
    429  1.1.1.4.2.2  jdolecek 
    430  1.1.1.4.2.2  jdolecek     Length1 = ACPI_PTR_DIFF (EndTag, Operand1->Buffer.Pointer);
    431  1.1.1.4.2.2  jdolecek 
    432  1.1.1.4.2.2  jdolecek     /* Combine both lengths, minimum size will be 2 for EndTag */
    433  1.1.1.4.2.2  jdolecek 
    434  1.1.1.4.2.2  jdolecek     NewLength = Length0 + Length1 + sizeof (AML_RESOURCE_END_TAG);
    435  1.1.1.4.2.2  jdolecek 
    436  1.1.1.4.2.2  jdolecek     /* Create a new buffer object for the result (with one EndTag) */
    437  1.1.1.4.2.2  jdolecek 
    438  1.1.1.4.2.2  jdolecek     ReturnDesc = AcpiUtCreateBufferObject (NewLength);
    439  1.1.1.4.2.2  jdolecek     if (!ReturnDesc)
    440  1.1.1.4.2.2  jdolecek     {
    441  1.1.1.4.2.2  jdolecek         return_ACPI_STATUS (AE_NO_MEMORY);
    442  1.1.1.4.2.2  jdolecek     }
    443  1.1.1.4.2.2  jdolecek 
    444  1.1.1.4.2.2  jdolecek     /*
    445  1.1.1.4.2.2  jdolecek      * Copy the templates to the new buffer, 0 first, then 1 follows. One
    446  1.1.1.4.2.2  jdolecek      * EndTag descriptor is copied from Operand1.
    447  1.1.1.4.2.2  jdolecek      */
    448  1.1.1.4.2.2  jdolecek     NewBuf = ReturnDesc->Buffer.Pointer;
    449  1.1.1.4.2.2  jdolecek     memcpy (NewBuf, Operand0->Buffer.Pointer, Length0);
    450  1.1.1.4.2.2  jdolecek     memcpy (NewBuf + Length0, Operand1->Buffer.Pointer, Length1);
    451  1.1.1.4.2.2  jdolecek 
    452  1.1.1.4.2.2  jdolecek     /* Insert EndTag and set the checksum to zero, means "ignore checksum" */
    453  1.1.1.4.2.2  jdolecek 
    454  1.1.1.4.2.2  jdolecek     NewBuf[NewLength - 1] = 0;
    455  1.1.1.4.2.2  jdolecek     NewBuf[NewLength - 2] = ACPI_RESOURCE_NAME_END_TAG | 1;
    456  1.1.1.4.2.2  jdolecek 
    457  1.1.1.4.2.2  jdolecek     /* Return the completed resource template */
    458  1.1.1.4.2.2  jdolecek 
    459  1.1.1.4.2.2  jdolecek     *ActualReturnDesc = ReturnDesc;
    460  1.1.1.4.2.2  jdolecek     return_ACPI_STATUS (AE_OK);
    461  1.1.1.4.2.2  jdolecek }
    462