Home | History | Annotate | Line # | Download | only in executer
exfield.c revision 1.1.1.14
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3  1.1.1.10  christos  * Module Name: exfield - AML execution - FieldUnit read/write
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8  1.1.1.13  christos  * Copyright (C) 2000 - 2020, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13   1.1.1.2    jruoho  * are met:
     14   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.1.1.2    jruoho  *    without modification.
     17   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.1.1.2    jruoho  *    binary redistribution.
     22   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25   1.1.1.2    jruoho  *
     26   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.1.1.2    jruoho  * Software Foundation.
     29   1.1.1.2    jruoho  *
     30   1.1.1.2    jruoho  * NO WARRANTY
     31   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33   1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.1.1.2    jruoho  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "acpi.h"
     45       1.1    jruoho #include "accommon.h"
     46       1.1    jruoho #include "acdispat.h"
     47       1.1    jruoho #include "acinterp.h"
     48   1.1.1.4  christos #include "amlcode.h"
     49       1.1    jruoho 
     50       1.1    jruoho 
     51       1.1    jruoho #define _COMPONENT          ACPI_EXECUTER
     52       1.1    jruoho         ACPI_MODULE_NAME    ("exfield")
     53       1.1    jruoho 
     54   1.1.1.4  christos 
     55  1.1.1.10  christos /*
     56  1.1.1.10  christos  * This table maps the various Attrib protocols to the byte transfer
     57  1.1.1.10  christos  * length. Used for the generic serial bus.
     58  1.1.1.10  christos  */
     59  1.1.1.10  christos #define ACPI_INVALID_PROTOCOL_ID        0x80
     60  1.1.1.10  christos #define ACPI_MAX_PROTOCOL_ID            0x0F
     61  1.1.1.10  christos 
     62  1.1.1.14  christos static const UINT8      AcpiProtocolLengths[] =
     63  1.1.1.10  christos {
     64  1.1.1.10  christos     ACPI_INVALID_PROTOCOL_ID,   /* 0 - reserved */
     65  1.1.1.10  christos     ACPI_INVALID_PROTOCOL_ID,   /* 1 - reserved */
     66  1.1.1.10  christos     0x00,                       /* 2 - ATTRIB_QUICK */
     67  1.1.1.10  christos     ACPI_INVALID_PROTOCOL_ID,   /* 3 - reserved */
     68  1.1.1.10  christos     0x01,                       /* 4 - ATTRIB_SEND_RECEIVE */
     69  1.1.1.10  christos     ACPI_INVALID_PROTOCOL_ID,   /* 5 - reserved */
     70  1.1.1.10  christos     0x01,                       /* 6 - ATTRIB_BYTE */
     71  1.1.1.10  christos     ACPI_INVALID_PROTOCOL_ID,   /* 7 - reserved */
     72  1.1.1.10  christos     0x02,                       /* 8 - ATTRIB_WORD */
     73  1.1.1.10  christos     ACPI_INVALID_PROTOCOL_ID,   /* 9 - reserved */
     74  1.1.1.10  christos     0xFF,                       /* A - ATTRIB_BLOCK  */
     75  1.1.1.10  christos     0xFF,                       /* B - ATTRIB_BYTES */
     76  1.1.1.10  christos     0x02,                       /* C - ATTRIB_PROCESS_CALL */
     77  1.1.1.10  christos     0xFF,                       /* D - ATTRIB_BLOCK_PROCESS_CALL */
     78  1.1.1.10  christos     0xFF,                       /* E - ATTRIB_RAW_BYTES */
     79  1.1.1.10  christos     0xFF                        /* F - ATTRIB_RAW_PROCESS_BYTES */
     80  1.1.1.10  christos };
     81   1.1.1.4  christos 
     82  1.1.1.11  christos #define PCC_MASTER_SUBSPACE     3
     83  1.1.1.11  christos 
     84  1.1.1.11  christos /*
     85  1.1.1.11  christos  * The following macros determine a given offset is a COMD field.
     86  1.1.1.11  christos  * According to the specification, generic subspaces (types 0-2) contains a
     87  1.1.1.11  christos  * 2-byte COMD field at offset 4 and master subspaces (type 3) contains a 4-byte
     88  1.1.1.11  christos  * COMD field starting at offset 12.
     89  1.1.1.11  christos  */
     90  1.1.1.11  christos #define GENERIC_SUBSPACE_COMMAND(a)     (4 == a || a == 5)
     91  1.1.1.11  christos #define MASTER_SUBSPACE_COMMAND(a)      (12 <= a && a <= 15)
     92  1.1.1.11  christos 
     93   1.1.1.4  christos 
     94   1.1.1.4  christos /*******************************************************************************
     95   1.1.1.4  christos  *
     96  1.1.1.10  christos  * FUNCTION:    AcpiExGetProtocolBufferLength
     97   1.1.1.4  christos  *
     98  1.1.1.10  christos  * PARAMETERS:  ProtocolId      - The type of the protocol indicated by region
     99   1.1.1.4  christos  *                                field access attributes
    100  1.1.1.10  christos  *              ReturnLength    - Where the protocol byte transfer length is
    101  1.1.1.10  christos  *                                returned
    102   1.1.1.4  christos  *
    103  1.1.1.10  christos  * RETURN:      Status and decoded byte transfer length
    104   1.1.1.4  christos  *
    105   1.1.1.4  christos  * DESCRIPTION: This routine returns the length of the GenericSerialBus
    106   1.1.1.4  christos  *              protocol bytes
    107   1.1.1.4  christos  *
    108   1.1.1.4  christos  ******************************************************************************/
    109   1.1.1.4  christos 
    110  1.1.1.10  christos ACPI_STATUS
    111  1.1.1.10  christos AcpiExGetProtocolBufferLength (
    112  1.1.1.10  christos     UINT32                  ProtocolId,
    113  1.1.1.10  christos     UINT32                  *ReturnLength)
    114   1.1.1.4  christos {
    115   1.1.1.4  christos 
    116  1.1.1.10  christos     if ((ProtocolId > ACPI_MAX_PROTOCOL_ID) ||
    117  1.1.1.10  christos         (AcpiProtocolLengths[ProtocolId] == ACPI_INVALID_PROTOCOL_ID))
    118   1.1.1.4  christos     {
    119  1.1.1.10  christos         ACPI_ERROR ((AE_INFO,
    120  1.1.1.10  christos             "Invalid Field/AccessAs protocol ID: 0x%4.4X", ProtocolId));
    121   1.1.1.4  christos 
    122  1.1.1.10  christos         return (AE_AML_PROTOCOL);
    123   1.1.1.4  christos     }
    124   1.1.1.4  christos 
    125  1.1.1.10  christos     *ReturnLength = AcpiProtocolLengths[ProtocolId];
    126  1.1.1.10  christos     return (AE_OK);
    127   1.1.1.4  christos }
    128   1.1.1.4  christos 
    129       1.1    jruoho 
    130       1.1    jruoho /*******************************************************************************
    131       1.1    jruoho  *
    132       1.1    jruoho  * FUNCTION:    AcpiExReadDataFromField
    133       1.1    jruoho  *
    134       1.1    jruoho  * PARAMETERS:  WalkState           - Current execution state
    135       1.1    jruoho  *              ObjDesc             - The named field
    136       1.1    jruoho  *              RetBufferDesc       - Where the return data object is stored
    137       1.1    jruoho  *
    138       1.1    jruoho  * RETURN:      Status
    139       1.1    jruoho  *
    140   1.1.1.3  christos  * DESCRIPTION: Read from a named field. Returns either an Integer or a
    141  1.1.1.12  christos  *              Buffer, depending on the size of the field and whether if a
    142  1.1.1.12  christos  *              field is created by the CreateField() operator.
    143       1.1    jruoho  *
    144       1.1    jruoho  ******************************************************************************/
    145       1.1    jruoho 
    146       1.1    jruoho ACPI_STATUS
    147       1.1    jruoho AcpiExReadDataFromField (
    148       1.1    jruoho     ACPI_WALK_STATE         *WalkState,
    149       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc,
    150       1.1    jruoho     ACPI_OPERAND_OBJECT     **RetBufferDesc)
    151       1.1    jruoho {
    152       1.1    jruoho     ACPI_STATUS             Status;
    153       1.1    jruoho     ACPI_OPERAND_OBJECT     *BufferDesc;
    154       1.1    jruoho     void                    *Buffer;
    155  1.1.1.10  christos     UINT32                  BufferLength;
    156       1.1    jruoho 
    157       1.1    jruoho 
    158       1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (ExReadDataFromField, ObjDesc);
    159       1.1    jruoho 
    160       1.1    jruoho 
    161       1.1    jruoho     /* Parameter validation */
    162       1.1    jruoho 
    163       1.1    jruoho     if (!ObjDesc)
    164       1.1    jruoho     {
    165       1.1    jruoho         return_ACPI_STATUS (AE_AML_NO_OPERAND);
    166       1.1    jruoho     }
    167       1.1    jruoho     if (!RetBufferDesc)
    168       1.1    jruoho     {
    169       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    170       1.1    jruoho     }
    171       1.1    jruoho 
    172       1.1    jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
    173       1.1    jruoho     {
    174       1.1    jruoho         /*
    175       1.1    jruoho          * If the BufferField arguments have not been previously evaluated,
    176       1.1    jruoho          * evaluate them now and save the results.
    177       1.1    jruoho          */
    178       1.1    jruoho         if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
    179       1.1    jruoho         {
    180       1.1    jruoho             Status = AcpiDsGetBufferFieldArguments (ObjDesc);
    181       1.1    jruoho             if (ACPI_FAILURE (Status))
    182       1.1    jruoho             {
    183       1.1    jruoho                 return_ACPI_STATUS (Status);
    184       1.1    jruoho             }
    185       1.1    jruoho         }
    186       1.1    jruoho     }
    187       1.1    jruoho     else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
    188  1.1.1.10  christos         (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS ||
    189  1.1.1.10  christos          ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS ||
    190  1.1.1.10  christos          ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI))
    191       1.1    jruoho     {
    192  1.1.1.10  christos         /* SMBus, GSBus, IPMI serial */
    193       1.1    jruoho 
    194  1.1.1.10  christos         Status = AcpiExReadSerialBus (ObjDesc, RetBufferDesc);
    195  1.1.1.10  christos         return_ACPI_STATUS (Status);
    196       1.1    jruoho     }
    197       1.1    jruoho 
    198       1.1    jruoho     /*
    199       1.1    jruoho      * Allocate a buffer for the contents of the field.
    200       1.1    jruoho      *
    201       1.1    jruoho      * If the field is larger than the current integer width, create
    202   1.1.1.3  christos      * a BUFFER to hold it. Otherwise, use an INTEGER. This allows
    203       1.1    jruoho      * the use of arithmetic operators on the returned value if the
    204       1.1    jruoho      * field size is equal or smaller than an Integer.
    205       1.1    jruoho      *
    206  1.1.1.12  christos      * However, all buffer fields created by CreateField operator needs to
    207  1.1.1.12  christos      * remain as a buffer to match other AML interpreter implementations.
    208  1.1.1.12  christos      *
    209       1.1    jruoho      * Note: Field.length is in bits.
    210       1.1    jruoho      */
    211  1.1.1.10  christos     BufferLength = (ACPI_SIZE) ACPI_ROUND_BITS_UP_TO_BYTES (
    212   1.1.1.7  christos         ObjDesc->Field.BitLength);
    213   1.1.1.7  christos 
    214  1.1.1.12  christos     if (BufferLength > AcpiGbl_IntegerByteWidth ||
    215  1.1.1.12  christos         (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD &&
    216  1.1.1.12  christos         ObjDesc->BufferField.IsCreateField))
    217       1.1    jruoho     {
    218       1.1    jruoho         /* Field is too large for an Integer, create a Buffer instead */
    219       1.1    jruoho 
    220  1.1.1.10  christos         BufferDesc = AcpiUtCreateBufferObject (BufferLength);
    221       1.1    jruoho         if (!BufferDesc)
    222       1.1    jruoho         {
    223       1.1    jruoho             return_ACPI_STATUS (AE_NO_MEMORY);
    224       1.1    jruoho         }
    225       1.1    jruoho         Buffer = BufferDesc->Buffer.Pointer;
    226       1.1    jruoho     }
    227       1.1    jruoho     else
    228       1.1    jruoho     {
    229       1.1    jruoho         /* Field will fit within an Integer (normal case) */
    230       1.1    jruoho 
    231       1.1    jruoho         BufferDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
    232       1.1    jruoho         if (!BufferDesc)
    233       1.1    jruoho         {
    234       1.1    jruoho             return_ACPI_STATUS (AE_NO_MEMORY);
    235       1.1    jruoho         }
    236       1.1    jruoho 
    237  1.1.1.10  christos         BufferLength = AcpiGbl_IntegerByteWidth;
    238       1.1    jruoho         Buffer = &BufferDesc->Integer.Value;
    239       1.1    jruoho     }
    240       1.1    jruoho 
    241   1.1.1.4  christos     if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
    242   1.1.1.4  christos         (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO))
    243   1.1.1.4  christos     {
    244  1.1.1.10  christos         /* General Purpose I/O */
    245   1.1.1.4  christos 
    246  1.1.1.10  christos         Status = AcpiExReadGpio (ObjDesc, Buffer);
    247  1.1.1.10  christos         goto Exit;
    248   1.1.1.4  christos     }
    249  1.1.1.11  christos     else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
    250  1.1.1.11  christos         (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_PLATFORM_COMM))
    251  1.1.1.11  christos     {
    252  1.1.1.11  christos         /*
    253  1.1.1.11  christos          * Reading from a PCC field unit does not require the handler because
    254  1.1.1.11  christos          * it only requires reading from the InternalPccBuffer.
    255  1.1.1.11  christos          */
    256  1.1.1.11  christos         ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    257  1.1.1.11  christos             "PCC FieldRead bits %u\n", ObjDesc->Field.BitLength));
    258  1.1.1.11  christos 
    259  1.1.1.11  christos         memcpy (Buffer, ObjDesc->Field.RegionObj->Field.InternalPccBuffer +
    260  1.1.1.11  christos         ObjDesc->Field.BaseByteOffset, (ACPI_SIZE) ACPI_ROUND_BITS_UP_TO_BYTES (
    261  1.1.1.11  christos             ObjDesc->Field.BitLength));
    262  1.1.1.11  christos 
    263  1.1.1.11  christos         *RetBufferDesc = BufferDesc;
    264  1.1.1.11  christos         return AE_OK;
    265  1.1.1.11  christos     }
    266   1.1.1.4  christos 
    267       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    268       1.1    jruoho         "FieldRead [TO]:   Obj %p, Type %X, Buf %p, ByteLen %X\n",
    269  1.1.1.10  christos         ObjDesc, ObjDesc->Common.Type, Buffer, BufferLength));
    270       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    271       1.1    jruoho         "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n",
    272       1.1    jruoho         ObjDesc->CommonField.BitLength,
    273       1.1    jruoho         ObjDesc->CommonField.StartFieldBitOffset,
    274       1.1    jruoho         ObjDesc->CommonField.BaseByteOffset));
    275       1.1    jruoho 
    276       1.1    jruoho     /* Lock entire transaction if requested */
    277       1.1    jruoho 
    278       1.1    jruoho     AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
    279       1.1    jruoho 
    280       1.1    jruoho     /* Read from the field */
    281       1.1    jruoho 
    282  1.1.1.10  christos     Status = AcpiExExtractFromField (ObjDesc, Buffer, BufferLength);
    283       1.1    jruoho     AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
    284       1.1    jruoho 
    285       1.1    jruoho 
    286       1.1    jruoho Exit:
    287       1.1    jruoho     if (ACPI_FAILURE (Status))
    288       1.1    jruoho     {
    289       1.1    jruoho         AcpiUtRemoveReference (BufferDesc);
    290       1.1    jruoho     }
    291       1.1    jruoho     else
    292       1.1    jruoho     {
    293       1.1    jruoho         *RetBufferDesc = BufferDesc;
    294       1.1    jruoho     }
    295       1.1    jruoho 
    296       1.1    jruoho     return_ACPI_STATUS (Status);
    297       1.1    jruoho }
    298       1.1    jruoho 
    299       1.1    jruoho 
    300       1.1    jruoho /*******************************************************************************
    301       1.1    jruoho  *
    302       1.1    jruoho  * FUNCTION:    AcpiExWriteDataToField
    303       1.1    jruoho  *
    304       1.1    jruoho  * PARAMETERS:  SourceDesc          - Contains data to write
    305       1.1    jruoho  *              ObjDesc             - The named field
    306       1.1    jruoho  *              ResultDesc          - Where the return value is returned, if any
    307       1.1    jruoho  *
    308       1.1    jruoho  * RETURN:      Status
    309       1.1    jruoho  *
    310       1.1    jruoho  * DESCRIPTION: Write to a named field
    311       1.1    jruoho  *
    312       1.1    jruoho  ******************************************************************************/
    313       1.1    jruoho 
    314       1.1    jruoho ACPI_STATUS
    315       1.1    jruoho AcpiExWriteDataToField (
    316       1.1    jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
    317       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc,
    318       1.1    jruoho     ACPI_OPERAND_OBJECT     **ResultDesc)
    319       1.1    jruoho {
    320       1.1    jruoho     ACPI_STATUS             Status;
    321  1.1.1.10  christos     UINT32                  BufferLength;
    322  1.1.1.11  christos     UINT32                  DataLength;
    323       1.1    jruoho     void                    *Buffer;
    324       1.1    jruoho 
    325       1.1    jruoho 
    326       1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField, ObjDesc);
    327       1.1    jruoho 
    328       1.1    jruoho 
    329       1.1    jruoho     /* Parameter validation */
    330       1.1    jruoho 
    331       1.1    jruoho     if (!SourceDesc || !ObjDesc)
    332       1.1    jruoho     {
    333       1.1    jruoho         return_ACPI_STATUS (AE_AML_NO_OPERAND);
    334       1.1    jruoho     }
    335       1.1    jruoho 
    336       1.1    jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
    337       1.1    jruoho     {
    338       1.1    jruoho         /*
    339       1.1    jruoho          * If the BufferField arguments have not been previously evaluated,
    340       1.1    jruoho          * evaluate them now and save the results.
    341       1.1    jruoho          */
    342       1.1    jruoho         if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
    343       1.1    jruoho         {
    344       1.1    jruoho             Status = AcpiDsGetBufferFieldArguments (ObjDesc);
    345       1.1    jruoho             if (ACPI_FAILURE (Status))
    346       1.1    jruoho             {
    347       1.1    jruoho                 return_ACPI_STATUS (Status);
    348       1.1    jruoho             }
    349       1.1    jruoho         }
    350       1.1    jruoho     }
    351       1.1    jruoho     else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
    352  1.1.1.10  christos         (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO))
    353       1.1    jruoho     {
    354  1.1.1.10  christos         /* General Purpose I/O */
    355       1.1    jruoho 
    356  1.1.1.10  christos         Status = AcpiExWriteGpio (SourceDesc, ObjDesc, ResultDesc);
    357       1.1    jruoho         return_ACPI_STATUS (Status);
    358       1.1    jruoho     }
    359   1.1.1.4  christos     else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
    360  1.1.1.10  christos         (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS ||
    361  1.1.1.10  christos          ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS ||
    362  1.1.1.10  christos          ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI))
    363   1.1.1.4  christos     {
    364  1.1.1.10  christos         /* SMBus, GSBus, IPMI serial */
    365   1.1.1.4  christos 
    366  1.1.1.10  christos         Status = AcpiExWriteSerialBus (SourceDesc, ObjDesc, ResultDesc);
    367   1.1.1.4  christos         return_ACPI_STATUS (Status);
    368   1.1.1.4  christos     }
    369  1.1.1.11  christos     else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
    370  1.1.1.11  christos              (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_PLATFORM_COMM))
    371  1.1.1.11  christos     {
    372  1.1.1.11  christos         /*
    373  1.1.1.11  christos          * According to the spec a write to the COMD field will invoke the
    374  1.1.1.11  christos          * region handler. Otherwise, write to the PccInternal buffer. This
    375  1.1.1.11  christos          * implementation will use the offsets specified rather than the name
    376  1.1.1.11  christos          * of the field. This is considered safer because some firmware tools
    377  1.1.1.11  christos          * are known to obfiscate named objects.
    378  1.1.1.11  christos          */
    379  1.1.1.11  christos         DataLength = (ACPI_SIZE) ACPI_ROUND_BITS_UP_TO_BYTES (
    380  1.1.1.11  christos             ObjDesc->Field.BitLength);
    381  1.1.1.11  christos         memcpy (ObjDesc->Field.RegionObj->Field.InternalPccBuffer +
    382  1.1.1.11  christos             ObjDesc->Field.BaseByteOffset,
    383  1.1.1.11  christos             SourceDesc->Buffer.Pointer, DataLength);
    384  1.1.1.11  christos 
    385  1.1.1.11  christos         if ((ObjDesc->Field.RegionObj->Region.Address == PCC_MASTER_SUBSPACE &&
    386  1.1.1.11  christos            MASTER_SUBSPACE_COMMAND (ObjDesc->Field.BaseByteOffset)) ||
    387  1.1.1.11  christos            GENERIC_SUBSPACE_COMMAND (ObjDesc->Field.BaseByteOffset))
    388  1.1.1.11  christos         {
    389  1.1.1.11  christos             /* Perform the write */
    390  1.1.1.11  christos 
    391  1.1.1.11  christos             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    392  1.1.1.11  christos                 "PCC COMD field has been written. Invoking PCC handler now.\n"));
    393  1.1.1.11  christos 
    394  1.1.1.11  christos             Status = AcpiExAccessRegion (
    395  1.1.1.11  christos                 ObjDesc, 0, (UINT64 *) ObjDesc->Field.RegionObj->Field.InternalPccBuffer,
    396  1.1.1.11  christos                 ACPI_WRITE);
    397  1.1.1.11  christos             return_ACPI_STATUS (Status);
    398  1.1.1.11  christos         }
    399  1.1.1.11  christos         return (AE_OK);
    400  1.1.1.11  christos     }
    401  1.1.1.11  christos 
    402       1.1    jruoho 
    403       1.1    jruoho     /* Get a pointer to the data to be written */
    404       1.1    jruoho 
    405       1.1    jruoho     switch (SourceDesc->Common.Type)
    406       1.1    jruoho     {
    407       1.1    jruoho     case ACPI_TYPE_INTEGER:
    408   1.1.1.3  christos 
    409       1.1    jruoho         Buffer = &SourceDesc->Integer.Value;
    410  1.1.1.10  christos         BufferLength = sizeof (SourceDesc->Integer.Value);
    411       1.1    jruoho         break;
    412       1.1    jruoho 
    413       1.1    jruoho     case ACPI_TYPE_BUFFER:
    414   1.1.1.3  christos 
    415       1.1    jruoho         Buffer = SourceDesc->Buffer.Pointer;
    416  1.1.1.10  christos         BufferLength = SourceDesc->Buffer.Length;
    417       1.1    jruoho         break;
    418       1.1    jruoho 
    419       1.1    jruoho     case ACPI_TYPE_STRING:
    420   1.1.1.3  christos 
    421       1.1    jruoho         Buffer = SourceDesc->String.Pointer;
    422  1.1.1.10  christos         BufferLength = SourceDesc->String.Length;
    423       1.1    jruoho         break;
    424       1.1    jruoho 
    425       1.1    jruoho     default:
    426       1.1    jruoho         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    427       1.1    jruoho     }
    428       1.1    jruoho 
    429       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    430       1.1    jruoho         "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
    431       1.1    jruoho         SourceDesc, AcpiUtGetTypeName (SourceDesc->Common.Type),
    432  1.1.1.10  christos         SourceDesc->Common.Type, Buffer, BufferLength));
    433       1.1    jruoho 
    434       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    435       1.1    jruoho         "FieldWrite [TO]:   Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n",
    436       1.1    jruoho         ObjDesc, AcpiUtGetTypeName (ObjDesc->Common.Type),
    437       1.1    jruoho         ObjDesc->Common.Type,
    438       1.1    jruoho         ObjDesc->CommonField.BitLength,
    439       1.1    jruoho         ObjDesc->CommonField.StartFieldBitOffset,
    440       1.1    jruoho         ObjDesc->CommonField.BaseByteOffset));
    441       1.1    jruoho 
    442       1.1    jruoho     /* Lock entire transaction if requested */
    443       1.1    jruoho 
    444       1.1    jruoho     AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
    445       1.1    jruoho 
    446       1.1    jruoho     /* Write to the field */
    447       1.1    jruoho 
    448  1.1.1.10  christos     Status = AcpiExInsertIntoField (ObjDesc, Buffer, BufferLength);
    449       1.1    jruoho     AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
    450       1.1    jruoho     return_ACPI_STATUS (Status);
    451       1.1    jruoho }
    452