Home | History | Annotate | Line # | Download | only in executer
exfield.c revision 1.1.1.2.8.2
      1  1.1.1.2.8.2  jruoho /******************************************************************************
      2  1.1.1.2.8.2  jruoho  *
      3  1.1.1.2.8.2  jruoho  * Module Name: exfield - ACPI AML (p-code) execution - field manipulation
      4  1.1.1.2.8.2  jruoho  *
      5  1.1.1.2.8.2  jruoho  *****************************************************************************/
      6  1.1.1.2.8.2  jruoho 
      7  1.1.1.2.8.2  jruoho /*
      8  1.1.1.2.8.2  jruoho  * Copyright (C) 2000 - 2011, Intel Corp.
      9  1.1.1.2.8.2  jruoho  * All rights reserved.
     10  1.1.1.2.8.2  jruoho  *
     11  1.1.1.2.8.2  jruoho  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2.8.2  jruoho  * modification, are permitted provided that the following conditions
     13  1.1.1.2.8.2  jruoho  * are met:
     14  1.1.1.2.8.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2.8.2  jruoho  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2.8.2  jruoho  *    without modification.
     17  1.1.1.2.8.2  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2.8.2  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2.8.2  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2.8.2  jruoho  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2.8.2  jruoho  *    binary redistribution.
     22  1.1.1.2.8.2  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2.8.2  jruoho  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2.8.2  jruoho  *    from this software without specific prior written permission.
     25  1.1.1.2.8.2  jruoho  *
     26  1.1.1.2.8.2  jruoho  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2.8.2  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2.8.2  jruoho  * Software Foundation.
     29  1.1.1.2.8.2  jruoho  *
     30  1.1.1.2.8.2  jruoho  * NO WARRANTY
     31  1.1.1.2.8.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2.8.2  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2.8.2  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2.8.2  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2.8.2  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2.8.2  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2.8.2  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2.8.2  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2.8.2  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2.8.2  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2.8.2  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2.8.2  jruoho  */
     43  1.1.1.2.8.2  jruoho 
     44  1.1.1.2.8.2  jruoho 
     45  1.1.1.2.8.2  jruoho #define __EXFIELD_C__
     46  1.1.1.2.8.2  jruoho 
     47  1.1.1.2.8.2  jruoho #include "acpi.h"
     48  1.1.1.2.8.2  jruoho #include "accommon.h"
     49  1.1.1.2.8.2  jruoho #include "acdispat.h"
     50  1.1.1.2.8.2  jruoho #include "acinterp.h"
     51  1.1.1.2.8.2  jruoho 
     52  1.1.1.2.8.2  jruoho 
     53  1.1.1.2.8.2  jruoho #define _COMPONENT          ACPI_EXECUTER
     54  1.1.1.2.8.2  jruoho         ACPI_MODULE_NAME    ("exfield")
     55  1.1.1.2.8.2  jruoho 
     56  1.1.1.2.8.2  jruoho 
     57  1.1.1.2.8.2  jruoho /*******************************************************************************
     58  1.1.1.2.8.2  jruoho  *
     59  1.1.1.2.8.2  jruoho  * FUNCTION:    AcpiExReadDataFromField
     60  1.1.1.2.8.2  jruoho  *
     61  1.1.1.2.8.2  jruoho  * PARAMETERS:  WalkState           - Current execution state
     62  1.1.1.2.8.2  jruoho  *              ObjDesc             - The named field
     63  1.1.1.2.8.2  jruoho  *              RetBufferDesc       - Where the return data object is stored
     64  1.1.1.2.8.2  jruoho  *
     65  1.1.1.2.8.2  jruoho  * RETURN:      Status
     66  1.1.1.2.8.2  jruoho  *
     67  1.1.1.2.8.2  jruoho  * DESCRIPTION: Read from a named field.  Returns either an Integer or a
     68  1.1.1.2.8.2  jruoho  *              Buffer, depending on the size of the field.
     69  1.1.1.2.8.2  jruoho  *
     70  1.1.1.2.8.2  jruoho  ******************************************************************************/
     71  1.1.1.2.8.2  jruoho 
     72  1.1.1.2.8.2  jruoho ACPI_STATUS
     73  1.1.1.2.8.2  jruoho AcpiExReadDataFromField (
     74  1.1.1.2.8.2  jruoho     ACPI_WALK_STATE         *WalkState,
     75  1.1.1.2.8.2  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc,
     76  1.1.1.2.8.2  jruoho     ACPI_OPERAND_OBJECT     **RetBufferDesc)
     77  1.1.1.2.8.2  jruoho {
     78  1.1.1.2.8.2  jruoho     ACPI_STATUS             Status;
     79  1.1.1.2.8.2  jruoho     ACPI_OPERAND_OBJECT     *BufferDesc;
     80  1.1.1.2.8.2  jruoho     ACPI_SIZE               Length;
     81  1.1.1.2.8.2  jruoho     void                    *Buffer;
     82  1.1.1.2.8.2  jruoho     UINT32                  Function;
     83  1.1.1.2.8.2  jruoho 
     84  1.1.1.2.8.2  jruoho 
     85  1.1.1.2.8.2  jruoho     ACPI_FUNCTION_TRACE_PTR (ExReadDataFromField, ObjDesc);
     86  1.1.1.2.8.2  jruoho 
     87  1.1.1.2.8.2  jruoho 
     88  1.1.1.2.8.2  jruoho     /* Parameter validation */
     89  1.1.1.2.8.2  jruoho 
     90  1.1.1.2.8.2  jruoho     if (!ObjDesc)
     91  1.1.1.2.8.2  jruoho     {
     92  1.1.1.2.8.2  jruoho         return_ACPI_STATUS (AE_AML_NO_OPERAND);
     93  1.1.1.2.8.2  jruoho     }
     94  1.1.1.2.8.2  jruoho     if (!RetBufferDesc)
     95  1.1.1.2.8.2  jruoho     {
     96  1.1.1.2.8.2  jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
     97  1.1.1.2.8.2  jruoho     }
     98  1.1.1.2.8.2  jruoho 
     99  1.1.1.2.8.2  jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
    100  1.1.1.2.8.2  jruoho     {
    101  1.1.1.2.8.2  jruoho         /*
    102  1.1.1.2.8.2  jruoho          * If the BufferField arguments have not been previously evaluated,
    103  1.1.1.2.8.2  jruoho          * evaluate them now and save the results.
    104  1.1.1.2.8.2  jruoho          */
    105  1.1.1.2.8.2  jruoho         if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
    106  1.1.1.2.8.2  jruoho         {
    107  1.1.1.2.8.2  jruoho             Status = AcpiDsGetBufferFieldArguments (ObjDesc);
    108  1.1.1.2.8.2  jruoho             if (ACPI_FAILURE (Status))
    109  1.1.1.2.8.2  jruoho             {
    110  1.1.1.2.8.2  jruoho                 return_ACPI_STATUS (Status);
    111  1.1.1.2.8.2  jruoho             }
    112  1.1.1.2.8.2  jruoho         }
    113  1.1.1.2.8.2  jruoho     }
    114  1.1.1.2.8.2  jruoho     else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
    115  1.1.1.2.8.2  jruoho              (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS ||
    116  1.1.1.2.8.2  jruoho               ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI))
    117  1.1.1.2.8.2  jruoho     {
    118  1.1.1.2.8.2  jruoho         /*
    119  1.1.1.2.8.2  jruoho          * This is an SMBus or IPMI read. We must create a buffer to hold
    120  1.1.1.2.8.2  jruoho          * the data and then directly access the region handler.
    121  1.1.1.2.8.2  jruoho          *
    122  1.1.1.2.8.2  jruoho          * Note: Smbus protocol value is passed in upper 16-bits of Function
    123  1.1.1.2.8.2  jruoho          */
    124  1.1.1.2.8.2  jruoho         if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS)
    125  1.1.1.2.8.2  jruoho         {
    126  1.1.1.2.8.2  jruoho             Length = ACPI_SMBUS_BUFFER_SIZE;
    127  1.1.1.2.8.2  jruoho             Function = ACPI_READ | (ObjDesc->Field.Attribute << 16);
    128  1.1.1.2.8.2  jruoho         }
    129  1.1.1.2.8.2  jruoho         else /* IPMI */
    130  1.1.1.2.8.2  jruoho         {
    131  1.1.1.2.8.2  jruoho             Length = ACPI_IPMI_BUFFER_SIZE;
    132  1.1.1.2.8.2  jruoho             Function = ACPI_READ;
    133  1.1.1.2.8.2  jruoho         }
    134  1.1.1.2.8.2  jruoho 
    135  1.1.1.2.8.2  jruoho         BufferDesc = AcpiUtCreateBufferObject (Length);
    136  1.1.1.2.8.2  jruoho         if (!BufferDesc)
    137  1.1.1.2.8.2  jruoho         {
    138  1.1.1.2.8.2  jruoho             return_ACPI_STATUS (AE_NO_MEMORY);
    139  1.1.1.2.8.2  jruoho         }
    140  1.1.1.2.8.2  jruoho 
    141  1.1.1.2.8.2  jruoho         /* Lock entire transaction if requested */
    142  1.1.1.2.8.2  jruoho 
    143  1.1.1.2.8.2  jruoho         AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
    144  1.1.1.2.8.2  jruoho 
    145  1.1.1.2.8.2  jruoho         /* Call the region handler for the read */
    146  1.1.1.2.8.2  jruoho 
    147  1.1.1.2.8.2  jruoho         Status = AcpiExAccessRegion (ObjDesc, 0,
    148  1.1.1.2.8.2  jruoho                     ACPI_CAST_PTR (UINT64, BufferDesc->Buffer.Pointer),
    149  1.1.1.2.8.2  jruoho                     Function);
    150  1.1.1.2.8.2  jruoho         AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
    151  1.1.1.2.8.2  jruoho         goto Exit;
    152  1.1.1.2.8.2  jruoho     }
    153  1.1.1.2.8.2  jruoho 
    154  1.1.1.2.8.2  jruoho     /*
    155  1.1.1.2.8.2  jruoho      * Allocate a buffer for the contents of the field.
    156  1.1.1.2.8.2  jruoho      *
    157  1.1.1.2.8.2  jruoho      * If the field is larger than the current integer width, create
    158  1.1.1.2.8.2  jruoho      * a BUFFER to hold it.  Otherwise, use an INTEGER.  This allows
    159  1.1.1.2.8.2  jruoho      * the use of arithmetic operators on the returned value if the
    160  1.1.1.2.8.2  jruoho      * field size is equal or smaller than an Integer.
    161  1.1.1.2.8.2  jruoho      *
    162  1.1.1.2.8.2  jruoho      * Note: Field.length is in bits.
    163  1.1.1.2.8.2  jruoho      */
    164  1.1.1.2.8.2  jruoho     Length = (ACPI_SIZE) ACPI_ROUND_BITS_UP_TO_BYTES (ObjDesc->Field.BitLength);
    165  1.1.1.2.8.2  jruoho     if (Length > AcpiGbl_IntegerByteWidth)
    166  1.1.1.2.8.2  jruoho     {
    167  1.1.1.2.8.2  jruoho         /* Field is too large for an Integer, create a Buffer instead */
    168  1.1.1.2.8.2  jruoho 
    169  1.1.1.2.8.2  jruoho         BufferDesc = AcpiUtCreateBufferObject (Length);
    170  1.1.1.2.8.2  jruoho         if (!BufferDesc)
    171  1.1.1.2.8.2  jruoho         {
    172  1.1.1.2.8.2  jruoho             return_ACPI_STATUS (AE_NO_MEMORY);
    173  1.1.1.2.8.2  jruoho         }
    174  1.1.1.2.8.2  jruoho         Buffer = BufferDesc->Buffer.Pointer;
    175  1.1.1.2.8.2  jruoho     }
    176  1.1.1.2.8.2  jruoho     else
    177  1.1.1.2.8.2  jruoho     {
    178  1.1.1.2.8.2  jruoho         /* Field will fit within an Integer (normal case) */
    179  1.1.1.2.8.2  jruoho 
    180  1.1.1.2.8.2  jruoho         BufferDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
    181  1.1.1.2.8.2  jruoho         if (!BufferDesc)
    182  1.1.1.2.8.2  jruoho         {
    183  1.1.1.2.8.2  jruoho             return_ACPI_STATUS (AE_NO_MEMORY);
    184  1.1.1.2.8.2  jruoho         }
    185  1.1.1.2.8.2  jruoho 
    186  1.1.1.2.8.2  jruoho         Length = AcpiGbl_IntegerByteWidth;
    187  1.1.1.2.8.2  jruoho         Buffer = &BufferDesc->Integer.Value;
    188  1.1.1.2.8.2  jruoho     }
    189  1.1.1.2.8.2  jruoho 
    190  1.1.1.2.8.2  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    191  1.1.1.2.8.2  jruoho         "FieldRead [TO]:   Obj %p, Type %X, Buf %p, ByteLen %X\n",
    192  1.1.1.2.8.2  jruoho         ObjDesc, ObjDesc->Common.Type, Buffer, (UINT32) Length));
    193  1.1.1.2.8.2  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    194  1.1.1.2.8.2  jruoho         "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n",
    195  1.1.1.2.8.2  jruoho         ObjDesc->CommonField.BitLength,
    196  1.1.1.2.8.2  jruoho         ObjDesc->CommonField.StartFieldBitOffset,
    197  1.1.1.2.8.2  jruoho         ObjDesc->CommonField.BaseByteOffset));
    198  1.1.1.2.8.2  jruoho 
    199  1.1.1.2.8.2  jruoho     /* Lock entire transaction if requested */
    200  1.1.1.2.8.2  jruoho 
    201  1.1.1.2.8.2  jruoho     AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
    202  1.1.1.2.8.2  jruoho 
    203  1.1.1.2.8.2  jruoho     /* Read from the field */
    204  1.1.1.2.8.2  jruoho 
    205  1.1.1.2.8.2  jruoho     Status = AcpiExExtractFromField (ObjDesc, Buffer, (UINT32) Length);
    206  1.1.1.2.8.2  jruoho     AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
    207  1.1.1.2.8.2  jruoho 
    208  1.1.1.2.8.2  jruoho 
    209  1.1.1.2.8.2  jruoho Exit:
    210  1.1.1.2.8.2  jruoho     if (ACPI_FAILURE (Status))
    211  1.1.1.2.8.2  jruoho     {
    212  1.1.1.2.8.2  jruoho         AcpiUtRemoveReference (BufferDesc);
    213  1.1.1.2.8.2  jruoho     }
    214  1.1.1.2.8.2  jruoho     else
    215  1.1.1.2.8.2  jruoho     {
    216  1.1.1.2.8.2  jruoho         *RetBufferDesc = BufferDesc;
    217  1.1.1.2.8.2  jruoho     }
    218  1.1.1.2.8.2  jruoho 
    219  1.1.1.2.8.2  jruoho     return_ACPI_STATUS (Status);
    220  1.1.1.2.8.2  jruoho }
    221  1.1.1.2.8.2  jruoho 
    222  1.1.1.2.8.2  jruoho 
    223  1.1.1.2.8.2  jruoho /*******************************************************************************
    224  1.1.1.2.8.2  jruoho  *
    225  1.1.1.2.8.2  jruoho  * FUNCTION:    AcpiExWriteDataToField
    226  1.1.1.2.8.2  jruoho  *
    227  1.1.1.2.8.2  jruoho  * PARAMETERS:  SourceDesc          - Contains data to write
    228  1.1.1.2.8.2  jruoho  *              ObjDesc             - The named field
    229  1.1.1.2.8.2  jruoho  *              ResultDesc          - Where the return value is returned, if any
    230  1.1.1.2.8.2  jruoho  *
    231  1.1.1.2.8.2  jruoho  * RETURN:      Status
    232  1.1.1.2.8.2  jruoho  *
    233  1.1.1.2.8.2  jruoho  * DESCRIPTION: Write to a named field
    234  1.1.1.2.8.2  jruoho  *
    235  1.1.1.2.8.2  jruoho  ******************************************************************************/
    236  1.1.1.2.8.2  jruoho 
    237  1.1.1.2.8.2  jruoho ACPI_STATUS
    238  1.1.1.2.8.2  jruoho AcpiExWriteDataToField (
    239  1.1.1.2.8.2  jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
    240  1.1.1.2.8.2  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc,
    241  1.1.1.2.8.2  jruoho     ACPI_OPERAND_OBJECT     **ResultDesc)
    242  1.1.1.2.8.2  jruoho {
    243  1.1.1.2.8.2  jruoho     ACPI_STATUS             Status;
    244  1.1.1.2.8.2  jruoho     UINT32                  Length;
    245  1.1.1.2.8.2  jruoho     void                    *Buffer;
    246  1.1.1.2.8.2  jruoho     ACPI_OPERAND_OBJECT     *BufferDesc;
    247  1.1.1.2.8.2  jruoho     UINT32                  Function;
    248  1.1.1.2.8.2  jruoho 
    249  1.1.1.2.8.2  jruoho 
    250  1.1.1.2.8.2  jruoho     ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField, ObjDesc);
    251  1.1.1.2.8.2  jruoho 
    252  1.1.1.2.8.2  jruoho 
    253  1.1.1.2.8.2  jruoho     /* Parameter validation */
    254  1.1.1.2.8.2  jruoho 
    255  1.1.1.2.8.2  jruoho     if (!SourceDesc || !ObjDesc)
    256  1.1.1.2.8.2  jruoho     {
    257  1.1.1.2.8.2  jruoho         return_ACPI_STATUS (AE_AML_NO_OPERAND);
    258  1.1.1.2.8.2  jruoho     }
    259  1.1.1.2.8.2  jruoho 
    260  1.1.1.2.8.2  jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
    261  1.1.1.2.8.2  jruoho     {
    262  1.1.1.2.8.2  jruoho         /*
    263  1.1.1.2.8.2  jruoho          * If the BufferField arguments have not been previously evaluated,
    264  1.1.1.2.8.2  jruoho          * evaluate them now and save the results.
    265  1.1.1.2.8.2  jruoho          */
    266  1.1.1.2.8.2  jruoho         if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
    267  1.1.1.2.8.2  jruoho         {
    268  1.1.1.2.8.2  jruoho             Status = AcpiDsGetBufferFieldArguments (ObjDesc);
    269  1.1.1.2.8.2  jruoho             if (ACPI_FAILURE (Status))
    270  1.1.1.2.8.2  jruoho             {
    271  1.1.1.2.8.2  jruoho                 return_ACPI_STATUS (Status);
    272  1.1.1.2.8.2  jruoho             }
    273  1.1.1.2.8.2  jruoho         }
    274  1.1.1.2.8.2  jruoho     }
    275  1.1.1.2.8.2  jruoho     else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
    276  1.1.1.2.8.2  jruoho              (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS ||
    277  1.1.1.2.8.2  jruoho               ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI))
    278  1.1.1.2.8.2  jruoho     {
    279  1.1.1.2.8.2  jruoho         /*
    280  1.1.1.2.8.2  jruoho          * This is an SMBus or IPMI write. We will bypass the entire field
    281  1.1.1.2.8.2  jruoho          * mechanism and handoff the buffer directly to the handler. For
    282  1.1.1.2.8.2  jruoho          * these address spaces, the buffer is bi-directional; on a write,
    283  1.1.1.2.8.2  jruoho          * return data is returned in the same buffer.
    284  1.1.1.2.8.2  jruoho          *
    285  1.1.1.2.8.2  jruoho          * Source must be a buffer of sufficient size:
    286  1.1.1.2.8.2  jruoho          * ACPI_SMBUS_BUFFER_SIZE or ACPI_IPMI_BUFFER_SIZE.
    287  1.1.1.2.8.2  jruoho          *
    288  1.1.1.2.8.2  jruoho          * Note: SMBus protocol type is passed in upper 16-bits of Function
    289  1.1.1.2.8.2  jruoho          */
    290  1.1.1.2.8.2  jruoho         if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER)
    291  1.1.1.2.8.2  jruoho         {
    292  1.1.1.2.8.2  jruoho             ACPI_ERROR ((AE_INFO,
    293  1.1.1.2.8.2  jruoho                 "SMBus or IPMI write requires Buffer, found type %s",
    294  1.1.1.2.8.2  jruoho                 AcpiUtGetObjectTypeName (SourceDesc)));
    295  1.1.1.2.8.2  jruoho 
    296  1.1.1.2.8.2  jruoho             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    297  1.1.1.2.8.2  jruoho         }
    298  1.1.1.2.8.2  jruoho 
    299  1.1.1.2.8.2  jruoho         if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS)
    300  1.1.1.2.8.2  jruoho         {
    301  1.1.1.2.8.2  jruoho             Length = ACPI_SMBUS_BUFFER_SIZE;
    302  1.1.1.2.8.2  jruoho             Function = ACPI_WRITE | (ObjDesc->Field.Attribute << 16);
    303  1.1.1.2.8.2  jruoho         }
    304  1.1.1.2.8.2  jruoho         else /* IPMI */
    305  1.1.1.2.8.2  jruoho         {
    306  1.1.1.2.8.2  jruoho             Length = ACPI_IPMI_BUFFER_SIZE;
    307  1.1.1.2.8.2  jruoho             Function = ACPI_WRITE;
    308  1.1.1.2.8.2  jruoho         }
    309  1.1.1.2.8.2  jruoho 
    310  1.1.1.2.8.2  jruoho         if (SourceDesc->Buffer.Length < Length)
    311  1.1.1.2.8.2  jruoho         {
    312  1.1.1.2.8.2  jruoho             ACPI_ERROR ((AE_INFO,
    313  1.1.1.2.8.2  jruoho                 "SMBus or IPMI write requires Buffer of length %u, found length %u",
    314  1.1.1.2.8.2  jruoho                 Length, SourceDesc->Buffer.Length));
    315  1.1.1.2.8.2  jruoho 
    316  1.1.1.2.8.2  jruoho             return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
    317  1.1.1.2.8.2  jruoho         }
    318  1.1.1.2.8.2  jruoho 
    319  1.1.1.2.8.2  jruoho         /* Create the bi-directional buffer */
    320  1.1.1.2.8.2  jruoho 
    321  1.1.1.2.8.2  jruoho         BufferDesc = AcpiUtCreateBufferObject (Length);
    322  1.1.1.2.8.2  jruoho         if (!BufferDesc)
    323  1.1.1.2.8.2  jruoho         {
    324  1.1.1.2.8.2  jruoho             return_ACPI_STATUS (AE_NO_MEMORY);
    325  1.1.1.2.8.2  jruoho         }
    326  1.1.1.2.8.2  jruoho 
    327  1.1.1.2.8.2  jruoho         Buffer = BufferDesc->Buffer.Pointer;
    328  1.1.1.2.8.2  jruoho         ACPI_MEMCPY (Buffer, SourceDesc->Buffer.Pointer, Length);
    329  1.1.1.2.8.2  jruoho 
    330  1.1.1.2.8.2  jruoho         /* Lock entire transaction if requested */
    331  1.1.1.2.8.2  jruoho 
    332  1.1.1.2.8.2  jruoho         AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
    333  1.1.1.2.8.2  jruoho 
    334  1.1.1.2.8.2  jruoho         /*
    335  1.1.1.2.8.2  jruoho          * Perform the write (returns status and perhaps data in the
    336  1.1.1.2.8.2  jruoho          * same buffer)
    337  1.1.1.2.8.2  jruoho          */
    338  1.1.1.2.8.2  jruoho         Status = AcpiExAccessRegion (ObjDesc, 0,
    339  1.1.1.2.8.2  jruoho                     (UINT64 *) Buffer, Function);
    340  1.1.1.2.8.2  jruoho         AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
    341  1.1.1.2.8.2  jruoho 
    342  1.1.1.2.8.2  jruoho         *ResultDesc = BufferDesc;
    343  1.1.1.2.8.2  jruoho         return_ACPI_STATUS (Status);
    344  1.1.1.2.8.2  jruoho     }
    345  1.1.1.2.8.2  jruoho 
    346  1.1.1.2.8.2  jruoho     /* Get a pointer to the data to be written */
    347  1.1.1.2.8.2  jruoho 
    348  1.1.1.2.8.2  jruoho     switch (SourceDesc->Common.Type)
    349  1.1.1.2.8.2  jruoho     {
    350  1.1.1.2.8.2  jruoho     case ACPI_TYPE_INTEGER:
    351  1.1.1.2.8.2  jruoho         Buffer = &SourceDesc->Integer.Value;
    352  1.1.1.2.8.2  jruoho         Length = sizeof (SourceDesc->Integer.Value);
    353  1.1.1.2.8.2  jruoho         break;
    354  1.1.1.2.8.2  jruoho 
    355  1.1.1.2.8.2  jruoho     case ACPI_TYPE_BUFFER:
    356  1.1.1.2.8.2  jruoho         Buffer = SourceDesc->Buffer.Pointer;
    357  1.1.1.2.8.2  jruoho         Length = SourceDesc->Buffer.Length;
    358  1.1.1.2.8.2  jruoho         break;
    359  1.1.1.2.8.2  jruoho 
    360  1.1.1.2.8.2  jruoho     case ACPI_TYPE_STRING:
    361  1.1.1.2.8.2  jruoho         Buffer = SourceDesc->String.Pointer;
    362  1.1.1.2.8.2  jruoho         Length = SourceDesc->String.Length;
    363  1.1.1.2.8.2  jruoho         break;
    364  1.1.1.2.8.2  jruoho 
    365  1.1.1.2.8.2  jruoho     default:
    366  1.1.1.2.8.2  jruoho         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    367  1.1.1.2.8.2  jruoho     }
    368  1.1.1.2.8.2  jruoho 
    369  1.1.1.2.8.2  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    370  1.1.1.2.8.2  jruoho         "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
    371  1.1.1.2.8.2  jruoho         SourceDesc, AcpiUtGetTypeName (SourceDesc->Common.Type),
    372  1.1.1.2.8.2  jruoho         SourceDesc->Common.Type, Buffer, Length));
    373  1.1.1.2.8.2  jruoho 
    374  1.1.1.2.8.2  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    375  1.1.1.2.8.2  jruoho         "FieldWrite [TO]:   Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n",
    376  1.1.1.2.8.2  jruoho         ObjDesc, AcpiUtGetTypeName (ObjDesc->Common.Type),
    377  1.1.1.2.8.2  jruoho         ObjDesc->Common.Type,
    378  1.1.1.2.8.2  jruoho         ObjDesc->CommonField.BitLength,
    379  1.1.1.2.8.2  jruoho         ObjDesc->CommonField.StartFieldBitOffset,
    380  1.1.1.2.8.2  jruoho         ObjDesc->CommonField.BaseByteOffset));
    381  1.1.1.2.8.2  jruoho 
    382  1.1.1.2.8.2  jruoho     /* Lock entire transaction if requested */
    383  1.1.1.2.8.2  jruoho 
    384  1.1.1.2.8.2  jruoho     AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
    385  1.1.1.2.8.2  jruoho 
    386  1.1.1.2.8.2  jruoho     /* Write to the field */
    387  1.1.1.2.8.2  jruoho 
    388  1.1.1.2.8.2  jruoho     Status = AcpiExInsertIntoField (ObjDesc, Buffer, Length);
    389  1.1.1.2.8.2  jruoho     AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
    390  1.1.1.2.8.2  jruoho 
    391  1.1.1.2.8.2  jruoho     return_ACPI_STATUS (Status);
    392  1.1.1.2.8.2  jruoho }
    393  1.1.1.2.8.2  jruoho 
    394  1.1.1.2.8.2  jruoho 
    395