Home | History | Annotate | Line # | Download | only in namespace
nsconvert.c revision 1.1.1.14.6.1
      1           1.1  christos /******************************************************************************
      2           1.1  christos  *
      3           1.1  christos  * Module Name: nsconvert - Object conversions for objects returned by
      4           1.1  christos  *                          predefined methods
      5           1.1  christos  *
      6           1.1  christos  *****************************************************************************/
      7           1.1  christos 
      8           1.1  christos /*
      9  1.1.1.14.6.1   thorpej  * Copyright (C) 2000 - 2021, Intel Corp.
     10           1.1  christos  * All rights reserved.
     11           1.1  christos  *
     12           1.1  christos  * Redistribution and use in source and binary forms, with or without
     13           1.1  christos  * modification, are permitted provided that the following conditions
     14           1.1  christos  * are met:
     15           1.1  christos  * 1. Redistributions of source code must retain the above copyright
     16           1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     17           1.1  christos  *    without modification.
     18           1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19           1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     20           1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     21           1.1  christos  *    including a substantially similar Disclaimer requirement for further
     22           1.1  christos  *    binary redistribution.
     23           1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     24           1.1  christos  *    of any contributors may be used to endorse or promote products derived
     25           1.1  christos  *    from this software without specific prior written permission.
     26           1.1  christos  *
     27           1.1  christos  * Alternatively, this software may be distributed under the terms of the
     28           1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     29           1.1  christos  * Software Foundation.
     30           1.1  christos  *
     31           1.1  christos  * NO WARRANTY
     32           1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33           1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  1.1.1.14.6.1   thorpej  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     35           1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36           1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37           1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38           1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39           1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40           1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41           1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42           1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     43           1.1  christos  */
     44           1.1  christos 
     45           1.1  christos #include "acpi.h"
     46           1.1  christos #include "accommon.h"
     47           1.1  christos #include "acnamesp.h"
     48           1.1  christos #include "acinterp.h"
     49           1.1  christos #include "acpredef.h"
     50           1.1  christos #include "amlresrc.h"
     51           1.1  christos 
     52           1.1  christos #define _COMPONENT          ACPI_NAMESPACE
     53           1.1  christos         ACPI_MODULE_NAME    ("nsconvert")
     54           1.1  christos 
     55           1.1  christos 
     56           1.1  christos /*******************************************************************************
     57           1.1  christos  *
     58           1.1  christos  * FUNCTION:    AcpiNsConvertToInteger
     59           1.1  christos  *
     60           1.1  christos  * PARAMETERS:  OriginalObject      - Object to be converted
     61           1.1  christos  *              ReturnObject        - Where the new converted object is returned
     62           1.1  christos  *
     63           1.1  christos  * RETURN:      Status. AE_OK if conversion was successful.
     64           1.1  christos  *
     65           1.1  christos  * DESCRIPTION: Attempt to convert a String/Buffer object to an Integer.
     66           1.1  christos  *
     67           1.1  christos  ******************************************************************************/
     68           1.1  christos 
     69           1.1  christos ACPI_STATUS
     70           1.1  christos AcpiNsConvertToInteger (
     71           1.1  christos     ACPI_OPERAND_OBJECT     *OriginalObject,
     72           1.1  christos     ACPI_OPERAND_OBJECT     **ReturnObject)
     73           1.1  christos {
     74           1.1  christos     ACPI_OPERAND_OBJECT     *NewObject;
     75           1.1  christos     ACPI_STATUS             Status;
     76           1.1  christos     UINT64                  Value = 0;
     77           1.1  christos     UINT32                  i;
     78           1.1  christos 
     79           1.1  christos 
     80           1.1  christos     switch (OriginalObject->Common.Type)
     81           1.1  christos     {
     82           1.1  christos     case ACPI_TYPE_STRING:
     83           1.1  christos 
     84           1.1  christos         /* String-to-Integer conversion */
     85           1.1  christos 
     86       1.1.1.9  christos         Status = AcpiUtStrtoul64 (OriginalObject->String.Pointer, &Value);
     87           1.1  christos         if (ACPI_FAILURE (Status))
     88           1.1  christos         {
     89           1.1  christos             return (Status);
     90           1.1  christos         }
     91           1.1  christos         break;
     92           1.1  christos 
     93           1.1  christos     case ACPI_TYPE_BUFFER:
     94           1.1  christos 
     95           1.1  christos         /* Buffer-to-Integer conversion. Max buffer size is 64 bits. */
     96           1.1  christos 
     97           1.1  christos         if (OriginalObject->Buffer.Length > 8)
     98           1.1  christos         {
     99           1.1  christos             return (AE_AML_OPERAND_TYPE);
    100           1.1  christos         }
    101           1.1  christos 
    102           1.1  christos         /* Extract each buffer byte to create the integer */
    103           1.1  christos 
    104           1.1  christos         for (i = 0; i < OriginalObject->Buffer.Length; i++)
    105           1.1  christos         {
    106       1.1.1.5  christos             Value |= ((UINT64)
    107       1.1.1.5  christos                 OriginalObject->Buffer.Pointer[i] << (i * 8));
    108           1.1  christos         }
    109           1.1  christos         break;
    110           1.1  christos 
    111           1.1  christos     default:
    112           1.1  christos 
    113           1.1  christos         return (AE_AML_OPERAND_TYPE);
    114           1.1  christos     }
    115           1.1  christos 
    116           1.1  christos     NewObject = AcpiUtCreateIntegerObject (Value);
    117           1.1  christos     if (!NewObject)
    118           1.1  christos     {
    119           1.1  christos         return (AE_NO_MEMORY);
    120           1.1  christos     }
    121           1.1  christos 
    122           1.1  christos     *ReturnObject = NewObject;
    123           1.1  christos     return (AE_OK);
    124           1.1  christos }
    125           1.1  christos 
    126           1.1  christos 
    127           1.1  christos /*******************************************************************************
    128           1.1  christos  *
    129           1.1  christos  * FUNCTION:    AcpiNsConvertToString
    130           1.1  christos  *
    131           1.1  christos  * PARAMETERS:  OriginalObject      - Object to be converted
    132           1.1  christos  *              ReturnObject        - Where the new converted object is returned
    133           1.1  christos  *
    134           1.1  christos  * RETURN:      Status. AE_OK if conversion was successful.
    135           1.1  christos  *
    136           1.1  christos  * DESCRIPTION: Attempt to convert a Integer/Buffer object to a String.
    137           1.1  christos  *
    138           1.1  christos  ******************************************************************************/
    139           1.1  christos 
    140           1.1  christos ACPI_STATUS
    141           1.1  christos AcpiNsConvertToString (
    142           1.1  christos     ACPI_OPERAND_OBJECT     *OriginalObject,
    143           1.1  christos     ACPI_OPERAND_OBJECT     **ReturnObject)
    144           1.1  christos {
    145           1.1  christos     ACPI_OPERAND_OBJECT     *NewObject;
    146           1.1  christos     ACPI_SIZE               Length;
    147           1.1  christos     ACPI_STATUS             Status;
    148           1.1  christos 
    149           1.1  christos 
    150           1.1  christos     switch (OriginalObject->Common.Type)
    151           1.1  christos     {
    152           1.1  christos     case ACPI_TYPE_INTEGER:
    153           1.1  christos         /*
    154           1.1  christos          * Integer-to-String conversion. Commonly, convert
    155           1.1  christos          * an integer of value 0 to a NULL string. The last element of
    156           1.1  christos          * _BIF and _BIX packages occasionally need this fix.
    157           1.1  christos          */
    158           1.1  christos         if (OriginalObject->Integer.Value == 0)
    159           1.1  christos         {
    160           1.1  christos             /* Allocate a new NULL string object */
    161           1.1  christos 
    162           1.1  christos             NewObject = AcpiUtCreateStringObject (0);
    163           1.1  christos             if (!NewObject)
    164           1.1  christos             {
    165           1.1  christos                 return (AE_NO_MEMORY);
    166           1.1  christos             }
    167           1.1  christos         }
    168           1.1  christos         else
    169           1.1  christos         {
    170       1.1.1.5  christos             Status = AcpiExConvertToString (OriginalObject,
    171       1.1.1.5  christos                 &NewObject, ACPI_IMPLICIT_CONVERT_HEX);
    172           1.1  christos             if (ACPI_FAILURE (Status))
    173           1.1  christos             {
    174           1.1  christos                 return (Status);
    175           1.1  christos             }
    176           1.1  christos         }
    177           1.1  christos         break;
    178           1.1  christos 
    179           1.1  christos     case ACPI_TYPE_BUFFER:
    180           1.1  christos         /*
    181           1.1  christos          * Buffer-to-String conversion. Use a ToString
    182           1.1  christos          * conversion, no transform performed on the buffer data. The best
    183           1.1  christos          * example of this is the _BIF method, where the string data from
    184           1.1  christos          * the battery is often (incorrectly) returned as buffer object(s).
    185           1.1  christos          */
    186           1.1  christos         Length = 0;
    187           1.1  christos         while ((Length < OriginalObject->Buffer.Length) &&
    188           1.1  christos                 (OriginalObject->Buffer.Pointer[Length]))
    189           1.1  christos         {
    190           1.1  christos             Length++;
    191           1.1  christos         }
    192           1.1  christos 
    193           1.1  christos         /* Allocate a new string object */
    194           1.1  christos 
    195           1.1  christos         NewObject = AcpiUtCreateStringObject (Length);
    196           1.1  christos         if (!NewObject)
    197           1.1  christos         {
    198           1.1  christos             return (AE_NO_MEMORY);
    199           1.1  christos         }
    200           1.1  christos 
    201           1.1  christos         /*
    202           1.1  christos          * Copy the raw buffer data with no transform. String is already NULL
    203           1.1  christos          * terminated at Length+1.
    204           1.1  christos          */
    205       1.1.1.4  christos         memcpy (NewObject->String.Pointer,
    206           1.1  christos             OriginalObject->Buffer.Pointer, Length);
    207           1.1  christos         break;
    208           1.1  christos 
    209           1.1  christos     default:
    210           1.1  christos 
    211           1.1  christos         return (AE_AML_OPERAND_TYPE);
    212           1.1  christos     }
    213           1.1  christos 
    214           1.1  christos     *ReturnObject = NewObject;
    215           1.1  christos     return (AE_OK);
    216           1.1  christos }
    217           1.1  christos 
    218           1.1  christos 
    219           1.1  christos /*******************************************************************************
    220           1.1  christos  *
    221           1.1  christos  * FUNCTION:    AcpiNsConvertToBuffer
    222           1.1  christos  *
    223           1.1  christos  * PARAMETERS:  OriginalObject      - Object to be converted
    224           1.1  christos  *              ReturnObject        - Where the new converted object is returned
    225           1.1  christos  *
    226           1.1  christos  * RETURN:      Status. AE_OK if conversion was successful.
    227           1.1  christos  *
    228           1.1  christos  * DESCRIPTION: Attempt to convert a Integer/String/Package object to a Buffer.
    229           1.1  christos  *
    230           1.1  christos  ******************************************************************************/
    231           1.1  christos 
    232           1.1  christos ACPI_STATUS
    233           1.1  christos AcpiNsConvertToBuffer (
    234           1.1  christos     ACPI_OPERAND_OBJECT     *OriginalObject,
    235           1.1  christos     ACPI_OPERAND_OBJECT     **ReturnObject)
    236           1.1  christos {
    237           1.1  christos     ACPI_OPERAND_OBJECT     *NewObject;
    238           1.1  christos     ACPI_STATUS             Status;
    239           1.1  christos     ACPI_OPERAND_OBJECT     **Elements;
    240           1.1  christos     UINT32                  *DwordBuffer;
    241           1.1  christos     UINT32                  Count;
    242           1.1  christos     UINT32                  i;
    243           1.1  christos 
    244           1.1  christos 
    245           1.1  christos     switch (OriginalObject->Common.Type)
    246           1.1  christos     {
    247           1.1  christos     case ACPI_TYPE_INTEGER:
    248           1.1  christos         /*
    249           1.1  christos          * Integer-to-Buffer conversion.
    250           1.1  christos          * Convert the Integer to a packed-byte buffer. _MAT and other
    251           1.1  christos          * objects need this sometimes, if a read has been performed on a
    252           1.1  christos          * Field object that is less than or equal to the global integer
    253           1.1  christos          * size (32 or 64 bits).
    254           1.1  christos          */
    255           1.1  christos         Status = AcpiExConvertToBuffer (OriginalObject, &NewObject);
    256           1.1  christos         if (ACPI_FAILURE (Status))
    257           1.1  christos         {
    258           1.1  christos             return (Status);
    259           1.1  christos         }
    260           1.1  christos         break;
    261           1.1  christos 
    262           1.1  christos     case ACPI_TYPE_STRING:
    263           1.1  christos 
    264           1.1  christos         /* String-to-Buffer conversion. Simple data copy */
    265           1.1  christos 
    266       1.1.1.5  christos         NewObject = AcpiUtCreateBufferObject
    267       1.1.1.5  christos             (OriginalObject->String.Length);
    268           1.1  christos         if (!NewObject)
    269           1.1  christos         {
    270           1.1  christos             return (AE_NO_MEMORY);
    271           1.1  christos         }
    272           1.1  christos 
    273       1.1.1.4  christos         memcpy (NewObject->Buffer.Pointer,
    274           1.1  christos             OriginalObject->String.Pointer, OriginalObject->String.Length);
    275           1.1  christos         break;
    276           1.1  christos 
    277           1.1  christos     case ACPI_TYPE_PACKAGE:
    278           1.1  christos         /*
    279           1.1  christos          * This case is often seen for predefined names that must return a
    280           1.1  christos          * Buffer object with multiple DWORD integers within. For example,
    281           1.1  christos          * _FDE and _GTM. The Package can be converted to a Buffer.
    282           1.1  christos          */
    283           1.1  christos 
    284           1.1  christos         /* All elements of the Package must be integers */
    285           1.1  christos 
    286           1.1  christos         Elements = OriginalObject->Package.Elements;
    287           1.1  christos         Count = OriginalObject->Package.Count;
    288           1.1  christos 
    289           1.1  christos         for (i = 0; i < Count; i++)
    290           1.1  christos         {
    291           1.1  christos             if ((!*Elements) ||
    292           1.1  christos                 ((*Elements)->Common.Type != ACPI_TYPE_INTEGER))
    293           1.1  christos             {
    294           1.1  christos                 return (AE_AML_OPERAND_TYPE);
    295           1.1  christos             }
    296           1.1  christos             Elements++;
    297           1.1  christos         }
    298           1.1  christos 
    299           1.1  christos         /* Create the new buffer object to replace the Package */
    300           1.1  christos 
    301           1.1  christos         NewObject = AcpiUtCreateBufferObject (ACPI_MUL_4 (Count));
    302           1.1  christos         if (!NewObject)
    303           1.1  christos         {
    304           1.1  christos             return (AE_NO_MEMORY);
    305           1.1  christos         }
    306           1.1  christos 
    307           1.1  christos         /* Copy the package elements (integers) to the buffer as DWORDs */
    308           1.1  christos 
    309           1.1  christos         Elements = OriginalObject->Package.Elements;
    310           1.1  christos         DwordBuffer = ACPI_CAST_PTR (UINT32, NewObject->Buffer.Pointer);
    311           1.1  christos 
    312           1.1  christos         for (i = 0; i < Count; i++)
    313           1.1  christos         {
    314           1.1  christos             *DwordBuffer = (UINT32) (*Elements)->Integer.Value;
    315           1.1  christos             DwordBuffer++;
    316           1.1  christos             Elements++;
    317           1.1  christos         }
    318           1.1  christos         break;
    319           1.1  christos 
    320           1.1  christos     default:
    321           1.1  christos 
    322           1.1  christos         return (AE_AML_OPERAND_TYPE);
    323           1.1  christos     }
    324           1.1  christos 
    325           1.1  christos     *ReturnObject = NewObject;
    326           1.1  christos     return (AE_OK);
    327           1.1  christos }
    328           1.1  christos 
    329           1.1  christos 
    330           1.1  christos /*******************************************************************************
    331           1.1  christos  *
    332           1.1  christos  * FUNCTION:    AcpiNsConvertToUnicode
    333           1.1  christos  *
    334       1.1.1.5  christos  * PARAMETERS:  Scope               - Namespace node for the method/object
    335       1.1.1.5  christos  *              OriginalObject      - ASCII String Object to be converted
    336           1.1  christos  *              ReturnObject        - Where the new converted object is returned
    337           1.1  christos  *
    338           1.1  christos  * RETURN:      Status. AE_OK if conversion was successful.
    339           1.1  christos  *
    340           1.1  christos  * DESCRIPTION: Attempt to convert a String object to a Unicode string Buffer.
    341           1.1  christos  *
    342           1.1  christos  ******************************************************************************/
    343           1.1  christos 
    344           1.1  christos ACPI_STATUS
    345           1.1  christos AcpiNsConvertToUnicode (
    346       1.1.1.5  christos     ACPI_NAMESPACE_NODE     *Scope,
    347           1.1  christos     ACPI_OPERAND_OBJECT     *OriginalObject,
    348           1.1  christos     ACPI_OPERAND_OBJECT     **ReturnObject)
    349           1.1  christos {
    350           1.1  christos     ACPI_OPERAND_OBJECT     *NewObject;
    351           1.1  christos     char                    *AsciiString;
    352           1.1  christos     UINT16                  *UnicodeBuffer;
    353           1.1  christos     UINT32                  UnicodeLength;
    354           1.1  christos     UINT32                  i;
    355           1.1  christos 
    356           1.1  christos 
    357           1.1  christos     if (!OriginalObject)
    358           1.1  christos     {
    359           1.1  christos         return (AE_OK);
    360           1.1  christos     }
    361           1.1  christos 
    362           1.1  christos     /* If a Buffer was returned, it must be at least two bytes long */
    363           1.1  christos 
    364           1.1  christos     if (OriginalObject->Common.Type == ACPI_TYPE_BUFFER)
    365           1.1  christos     {
    366           1.1  christos         if (OriginalObject->Buffer.Length < 2)
    367           1.1  christos         {
    368           1.1  christos             return (AE_AML_OPERAND_VALUE);
    369           1.1  christos         }
    370           1.1  christos 
    371           1.1  christos         *ReturnObject = NULL;
    372           1.1  christos         return (AE_OK);
    373           1.1  christos     }
    374           1.1  christos 
    375           1.1  christos     /*
    376           1.1  christos      * The original object is an ASCII string. Convert this string to
    377           1.1  christos      * a unicode buffer.
    378           1.1  christos      */
    379           1.1  christos     AsciiString = OriginalObject->String.Pointer;
    380           1.1  christos     UnicodeLength = (OriginalObject->String.Length * 2) + 2;
    381           1.1  christos 
    382           1.1  christos     /* Create a new buffer object for the Unicode data */
    383           1.1  christos 
    384           1.1  christos     NewObject = AcpiUtCreateBufferObject (UnicodeLength);
    385           1.1  christos     if (!NewObject)
    386           1.1  christos     {
    387           1.1  christos         return (AE_NO_MEMORY);
    388           1.1  christos     }
    389           1.1  christos 
    390           1.1  christos     UnicodeBuffer = ACPI_CAST_PTR (UINT16, NewObject->Buffer.Pointer);
    391           1.1  christos 
    392           1.1  christos     /* Convert ASCII to Unicode */
    393           1.1  christos 
    394           1.1  christos     for (i = 0; i < OriginalObject->String.Length; i++)
    395           1.1  christos     {
    396           1.1  christos         UnicodeBuffer[i] = (UINT16) AsciiString[i];
    397           1.1  christos     }
    398           1.1  christos 
    399           1.1  christos     *ReturnObject = NewObject;
    400           1.1  christos     return (AE_OK);
    401           1.1  christos }
    402           1.1  christos 
    403           1.1  christos 
    404           1.1  christos /*******************************************************************************
    405           1.1  christos  *
    406           1.1  christos  * FUNCTION:    AcpiNsConvertToResource
    407           1.1  christos  *
    408       1.1.1.5  christos  * PARAMETERS:  Scope               - Namespace node for the method/object
    409       1.1.1.5  christos  *              OriginalObject      - Object to be converted
    410           1.1  christos  *              ReturnObject        - Where the new converted object is returned
    411           1.1  christos  *
    412           1.1  christos  * RETURN:      Status. AE_OK if conversion was successful
    413           1.1  christos  *
    414           1.1  christos  * DESCRIPTION: Attempt to convert a Integer object to a ResourceTemplate
    415           1.1  christos  *              Buffer.
    416           1.1  christos  *
    417           1.1  christos  ******************************************************************************/
    418           1.1  christos 
    419           1.1  christos ACPI_STATUS
    420           1.1  christos AcpiNsConvertToResource (
    421       1.1.1.5  christos     ACPI_NAMESPACE_NODE     *Scope,
    422           1.1  christos     ACPI_OPERAND_OBJECT     *OriginalObject,
    423           1.1  christos     ACPI_OPERAND_OBJECT     **ReturnObject)
    424           1.1  christos {
    425           1.1  christos     ACPI_OPERAND_OBJECT     *NewObject;
    426           1.1  christos     UINT8                   *Buffer;
    427           1.1  christos 
    428           1.1  christos 
    429           1.1  christos     /*
    430           1.1  christos      * We can fix the following cases for an expected resource template:
    431           1.1  christos      * 1. No return value (interpreter slack mode is disabled)
    432           1.1  christos      * 2. A "Return (Zero)" statement
    433           1.1  christos      * 3. A "Return empty buffer" statement
    434           1.1  christos      *
    435           1.1  christos      * We will return a buffer containing a single EndTag
    436           1.1  christos      * resource descriptor.
    437           1.1  christos      */
    438           1.1  christos     if (OriginalObject)
    439           1.1  christos     {
    440           1.1  christos         switch (OriginalObject->Common.Type)
    441           1.1  christos         {
    442           1.1  christos         case ACPI_TYPE_INTEGER:
    443           1.1  christos 
    444           1.1  christos             /* We can only repair an Integer==0 */
    445           1.1  christos 
    446           1.1  christos             if (OriginalObject->Integer.Value)
    447           1.1  christos             {
    448           1.1  christos                 return (AE_AML_OPERAND_TYPE);
    449           1.1  christos             }
    450           1.1  christos             break;
    451           1.1  christos 
    452           1.1  christos         case ACPI_TYPE_BUFFER:
    453           1.1  christos 
    454           1.1  christos             if (OriginalObject->Buffer.Length)
    455           1.1  christos             {
    456           1.1  christos                 /* Additional checks can be added in the future */
    457           1.1  christos 
    458           1.1  christos                 *ReturnObject = NULL;
    459           1.1  christos                 return (AE_OK);
    460           1.1  christos             }
    461           1.1  christos             break;
    462           1.1  christos 
    463           1.1  christos         case ACPI_TYPE_STRING:
    464           1.1  christos         default:
    465           1.1  christos 
    466           1.1  christos             return (AE_AML_OPERAND_TYPE);
    467           1.1  christos         }
    468           1.1  christos     }
    469           1.1  christos 
    470           1.1  christos     /* Create the new buffer object for the resource descriptor */
    471           1.1  christos 
    472           1.1  christos     NewObject = AcpiUtCreateBufferObject (2);
    473           1.1  christos     if (!NewObject)
    474           1.1  christos     {
    475           1.1  christos         return (AE_NO_MEMORY);
    476           1.1  christos     }
    477           1.1  christos 
    478           1.1  christos     Buffer = ACPI_CAST_PTR (UINT8, NewObject->Buffer.Pointer);
    479           1.1  christos 
    480           1.1  christos     /* Initialize the Buffer with a single EndTag descriptor */
    481           1.1  christos 
    482           1.1  christos     Buffer[0] = (ACPI_RESOURCE_NAME_END_TAG | ASL_RDESC_END_TAG_SIZE);
    483           1.1  christos     Buffer[1] = 0x00;
    484           1.1  christos 
    485           1.1  christos     *ReturnObject = NewObject;
    486           1.1  christos     return (AE_OK);
    487           1.1  christos }
    488       1.1.1.5  christos 
    489       1.1.1.5  christos 
    490       1.1.1.5  christos /*******************************************************************************
    491       1.1.1.5  christos  *
    492       1.1.1.5  christos  * FUNCTION:    AcpiNsConvertToReference
    493       1.1.1.5  christos  *
    494       1.1.1.5  christos  * PARAMETERS:  Scope               - Namespace node for the method/object
    495       1.1.1.5  christos  *              OriginalObject      - Object to be converted
    496       1.1.1.5  christos  *              ReturnObject        - Where the new converted object is returned
    497       1.1.1.5  christos  *
    498       1.1.1.5  christos  * RETURN:      Status. AE_OK if conversion was successful
    499       1.1.1.5  christos  *
    500       1.1.1.5  christos  * DESCRIPTION: Attempt to convert a Integer object to a ObjectReference.
    501       1.1.1.5  christos  *              Buffer.
    502       1.1.1.5  christos  *
    503       1.1.1.5  christos  ******************************************************************************/
    504       1.1.1.5  christos 
    505       1.1.1.5  christos ACPI_STATUS
    506       1.1.1.5  christos AcpiNsConvertToReference (
    507       1.1.1.5  christos     ACPI_NAMESPACE_NODE     *Scope,
    508       1.1.1.5  christos     ACPI_OPERAND_OBJECT     *OriginalObject,
    509       1.1.1.5  christos     ACPI_OPERAND_OBJECT     **ReturnObject)
    510       1.1.1.5  christos {
    511       1.1.1.5  christos     ACPI_OPERAND_OBJECT     *NewObject = NULL;
    512       1.1.1.5  christos     ACPI_STATUS             Status;
    513       1.1.1.5  christos     ACPI_NAMESPACE_NODE     *Node;
    514       1.1.1.5  christos     ACPI_GENERIC_STATE      ScopeInfo;
    515       1.1.1.5  christos     char                    *Name;
    516       1.1.1.5  christos 
    517       1.1.1.5  christos 
    518       1.1.1.5  christos     ACPI_FUNCTION_NAME (NsConvertToReference);
    519       1.1.1.5  christos 
    520       1.1.1.5  christos 
    521       1.1.1.5  christos     /* Convert path into internal presentation */
    522       1.1.1.5  christos 
    523       1.1.1.5  christos     Status = AcpiNsInternalizeName (OriginalObject->String.Pointer, &Name);
    524       1.1.1.5  christos     if (ACPI_FAILURE (Status))
    525       1.1.1.5  christos     {
    526       1.1.1.5  christos         return_ACPI_STATUS (Status);
    527       1.1.1.5  christos     }
    528       1.1.1.5  christos 
    529       1.1.1.5  christos     /* Find the namespace node */
    530       1.1.1.5  christos 
    531       1.1.1.5  christos     ScopeInfo.Scope.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Scope);
    532       1.1.1.5  christos     Status = AcpiNsLookup (&ScopeInfo, Name,
    533       1.1.1.5  christos         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
    534       1.1.1.5  christos         ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
    535       1.1.1.5  christos     if (ACPI_FAILURE (Status))
    536       1.1.1.5  christos     {
    537       1.1.1.5  christos         /* Check if we are resolving a named reference within a package */
    538       1.1.1.5  christos 
    539      1.1.1.10  christos         ACPI_ERROR_NAMESPACE (&ScopeInfo,
    540      1.1.1.10  christos             OriginalObject->String.Pointer, Status);
    541       1.1.1.5  christos         goto ErrorExit;
    542       1.1.1.5  christos     }
    543       1.1.1.5  christos 
    544       1.1.1.5  christos     /* Create and init a new internal ACPI object */
    545       1.1.1.5  christos 
    546       1.1.1.5  christos     NewObject = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
    547       1.1.1.5  christos     if (!NewObject)
    548       1.1.1.5  christos     {
    549       1.1.1.5  christos         Status = AE_NO_MEMORY;
    550       1.1.1.5  christos         goto ErrorExit;
    551       1.1.1.5  christos     }
    552       1.1.1.5  christos     NewObject->Reference.Node = Node;
    553       1.1.1.5  christos     NewObject->Reference.Object = Node->Object;
    554       1.1.1.5  christos     NewObject->Reference.Class = ACPI_REFCLASS_NAME;
    555       1.1.1.5  christos 
    556       1.1.1.5  christos     /*
    557       1.1.1.5  christos      * Increase reference of the object if needed (the object is likely a
    558       1.1.1.5  christos      * null for device nodes).
    559       1.1.1.5  christos      */
    560       1.1.1.5  christos     AcpiUtAddReference (Node->Object);
    561       1.1.1.5  christos 
    562       1.1.1.5  christos ErrorExit:
    563       1.1.1.5  christos     ACPI_FREE (Name);
    564       1.1.1.5  christos     *ReturnObject = NewObject;
    565      1.1.1.13  christos     return (Status);
    566       1.1.1.5  christos }
    567