17c478bd9Sstevel@tonic-gate /******************************************************************************
27c478bd9Sstevel@tonic-gate  *
37c478bd9Sstevel@tonic-gate  * Module Name: exfield - ACPI AML (p-code) execution - field manipulation
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  *****************************************************************************/
67c478bd9Sstevel@tonic-gate 
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi  *
9*35786f68SRobert Mustacchi  * 1. Copyright Notice
10*35786f68SRobert Mustacchi  *
11*35786f68SRobert Mustacchi  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
127c478bd9Sstevel@tonic-gate  * All rights reserved.
137c478bd9Sstevel@tonic-gate  *
14*35786f68SRobert Mustacchi  * 2. License
15*35786f68SRobert Mustacchi  *
16*35786f68SRobert Mustacchi  * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi  * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi  * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi  * property rights.
20*35786f68SRobert Mustacchi  *
21*35786f68SRobert Mustacchi  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi  * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi  * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi  * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi  *
28*35786f68SRobert Mustacchi  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi  * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi  * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi  * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi  * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi  * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi  * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi  *
37*35786f68SRobert Mustacchi  * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi  * conditions are met:
39*35786f68SRobert Mustacchi  *
40*35786f68SRobert Mustacchi  * 3. Conditions
41*35786f68SRobert Mustacchi  *
42*35786f68SRobert Mustacchi  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi  * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi  * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi  * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi  * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi  * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi  * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi  * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi  * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi  * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi  *
54*35786f68SRobert Mustacchi  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi  * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi  * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi  * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi  * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi  * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi  * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi  * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi  * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi  * make.
65*35786f68SRobert Mustacchi  *
66*35786f68SRobert Mustacchi  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi  * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi  * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi  * distribution.
71*35786f68SRobert Mustacchi  *
72*35786f68SRobert Mustacchi  * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi  * Intel Code.
74*35786f68SRobert Mustacchi  *
75*35786f68SRobert Mustacchi  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi  * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi  * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi  *
80*35786f68SRobert Mustacchi  * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi  *
82*35786f68SRobert Mustacchi  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi  * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi  *
90*35786f68SRobert Mustacchi  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi  * LIMITED REMEDY.
98*35786f68SRobert Mustacchi  *
99*35786f68SRobert Mustacchi  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi  * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi  * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi  * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi  * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi  * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi  * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi  * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi  * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi  * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi  * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi  * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi  * such license, approval or letter.
113*35786f68SRobert Mustacchi  *
114*35786f68SRobert Mustacchi  *****************************************************************************
115*35786f68SRobert Mustacchi  *
116*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi  * following license:
118*35786f68SRobert Mustacchi  *
11926f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
12026f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
12126f3cdf0SGordon Ross  * are met:
12226f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
12326f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
12426f3cdf0SGordon Ross  *    without modification.
12526f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12626f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
12726f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
12826f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
12926f3cdf0SGordon Ross  *    binary redistribution.
13026f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
13126f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
13226f3cdf0SGordon Ross  *    from this software without specific prior written permission.
1337c478bd9Sstevel@tonic-gate  *
13426f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13526f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13726f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi  *
146*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi  * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi  * Software Foundation.
149*35786f68SRobert Mustacchi  *
150*35786f68SRobert Mustacchi  *****************************************************************************/
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #include "acpi.h"
153aa2aa9a6SDana Myers #include "accommon.h"
1547c478bd9Sstevel@tonic-gate #include "acdispat.h"
1557c478bd9Sstevel@tonic-gate #include "acinterp.h"
1567b1019a6SJerry Jelinek #include "amlcode.h"
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate #define _COMPONENT          ACPI_EXECUTER
1607c478bd9Sstevel@tonic-gate         ACPI_MODULE_NAME    ("exfield")
1617c478bd9Sstevel@tonic-gate 
1627b1019a6SJerry Jelinek /* Local prototypes */
1637b1019a6SJerry Jelinek 
1647b1019a6SJerry Jelinek static UINT32
1657b1019a6SJerry Jelinek AcpiExGetSerialAccessLength (
1667b1019a6SJerry Jelinek     UINT32                  AccessorType,
1677b1019a6SJerry Jelinek     UINT32                  AccessLength);
1687b1019a6SJerry Jelinek 
1697b1019a6SJerry Jelinek 
1707b1019a6SJerry Jelinek /*******************************************************************************
1717b1019a6SJerry Jelinek  *
1727b1019a6SJerry Jelinek  * FUNCTION:    AcpiExGetSerialAccessLength
1737b1019a6SJerry Jelinek  *
1747b1019a6SJerry Jelinek  * PARAMETERS:  AccessorType    - The type of the protocol indicated by region
1757b1019a6SJerry Jelinek  *                                field access attributes
1767b1019a6SJerry Jelinek  *              AccessLength    - The access length of the region field
1777b1019a6SJerry Jelinek  *
1787b1019a6SJerry Jelinek  * RETURN:      Decoded access length
1797b1019a6SJerry Jelinek  *
1807b1019a6SJerry Jelinek  * DESCRIPTION: This routine returns the length of the GenericSerialBus
1817b1019a6SJerry Jelinek  *              protocol bytes
1827b1019a6SJerry Jelinek  *
1837b1019a6SJerry Jelinek  ******************************************************************************/
1847b1019a6SJerry Jelinek 
1857b1019a6SJerry Jelinek static UINT32
AcpiExGetSerialAccessLength(UINT32 AccessorType,UINT32 AccessLength)1867b1019a6SJerry Jelinek AcpiExGetSerialAccessLength (
1877b1019a6SJerry Jelinek     UINT32                  AccessorType,
1887b1019a6SJerry Jelinek     UINT32                  AccessLength)
1897b1019a6SJerry Jelinek {
1907b1019a6SJerry Jelinek     UINT32                  Length;
1917b1019a6SJerry Jelinek 
1927b1019a6SJerry Jelinek 
1937b1019a6SJerry Jelinek     switch (AccessorType)
1947b1019a6SJerry Jelinek     {
1957b1019a6SJerry Jelinek     case AML_FIELD_ATTRIB_QUICK:
1967b1019a6SJerry Jelinek 
1977b1019a6SJerry Jelinek         Length = 0;
1987b1019a6SJerry Jelinek         break;
1997b1019a6SJerry Jelinek 
2007b1019a6SJerry Jelinek     case AML_FIELD_ATTRIB_SEND_RCV:
2017b1019a6SJerry Jelinek     case AML_FIELD_ATTRIB_BYTE:
2027b1019a6SJerry Jelinek 
2037b1019a6SJerry Jelinek         Length = 1;
2047b1019a6SJerry Jelinek         break;
2057b1019a6SJerry Jelinek 
2067b1019a6SJerry Jelinek     case AML_FIELD_ATTRIB_WORD:
2077b1019a6SJerry Jelinek     case AML_FIELD_ATTRIB_WORD_CALL:
2087b1019a6SJerry Jelinek 
2097b1019a6SJerry Jelinek         Length = 2;
2107b1019a6SJerry Jelinek         break;
2117b1019a6SJerry Jelinek 
2127b1019a6SJerry Jelinek     case AML_FIELD_ATTRIB_MULTIBYTE:
2137b1019a6SJerry Jelinek     case AML_FIELD_ATTRIB_RAW_BYTES:
2147b1019a6SJerry Jelinek     case AML_FIELD_ATTRIB_RAW_PROCESS:
2157b1019a6SJerry Jelinek 
2167b1019a6SJerry Jelinek         Length = AccessLength;
2177b1019a6SJerry Jelinek         break;
2187b1019a6SJerry Jelinek 
2197b1019a6SJerry Jelinek     case AML_FIELD_ATTRIB_BLOCK:
2207b1019a6SJerry Jelinek     case AML_FIELD_ATTRIB_BLOCK_CALL:
2217b1019a6SJerry Jelinek     default:
2227b1019a6SJerry Jelinek 
2237b1019a6SJerry Jelinek         Length = ACPI_GSBUS_BUFFER_SIZE - 2;
2247b1019a6SJerry Jelinek         break;
2257b1019a6SJerry Jelinek     }
2267b1019a6SJerry Jelinek 
2277b1019a6SJerry Jelinek     return (Length);
2287b1019a6SJerry Jelinek }
2297b1019a6SJerry Jelinek 
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /*******************************************************************************
2327c478bd9Sstevel@tonic-gate  *
2337c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiExReadDataFromField
2347c478bd9Sstevel@tonic-gate  *
2357c478bd9Sstevel@tonic-gate  * PARAMETERS:  WalkState           - Current execution state
2367c478bd9Sstevel@tonic-gate  *              ObjDesc             - The named field
2377c478bd9Sstevel@tonic-gate  *              RetBufferDesc       - Where the return data object is stored
2387c478bd9Sstevel@tonic-gate  *
2397c478bd9Sstevel@tonic-gate  * RETURN:      Status
2407c478bd9Sstevel@tonic-gate  *
2417b1019a6SJerry Jelinek  * DESCRIPTION: Read from a named field. Returns either an Integer or a
2427c478bd9Sstevel@tonic-gate  *              Buffer, depending on the size of the field.
2437c478bd9Sstevel@tonic-gate  *
2447c478bd9Sstevel@tonic-gate  ******************************************************************************/
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiExReadDataFromField(ACPI_WALK_STATE * WalkState,ACPI_OPERAND_OBJECT * ObjDesc,ACPI_OPERAND_OBJECT ** RetBufferDesc)2477c478bd9Sstevel@tonic-gate AcpiExReadDataFromField (
2487c478bd9Sstevel@tonic-gate     ACPI_WALK_STATE         *WalkState,
2497c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     *ObjDesc,
2507c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     **RetBufferDesc)
2517c478bd9Sstevel@tonic-gate {
2527c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
2537c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     *BufferDesc;
2547c478bd9Sstevel@tonic-gate     ACPI_SIZE               Length;
2557c478bd9Sstevel@tonic-gate     void                    *Buffer;
25657190917SDana Myers     UINT32                  Function;
2577b1019a6SJerry Jelinek     UINT16                  AccessorType;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 
26027f7c583Smyers     ACPI_FUNCTION_TRACE_PTR (ExReadDataFromField, ObjDesc);
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate     /* Parameter validation */
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate     if (!ObjDesc)
2667c478bd9Sstevel@tonic-gate     {
2677c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (AE_AML_NO_OPERAND);
2687c478bd9Sstevel@tonic-gate     }
269450d6964Smyers     if (!RetBufferDesc)
270450d6964Smyers     {
271450d6964Smyers         return_ACPI_STATUS (AE_BAD_PARAMETER);
272450d6964Smyers     }
2737c478bd9Sstevel@tonic-gate 
274aa2aa9a6SDana Myers     if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
2757c478bd9Sstevel@tonic-gate     {
2767c478bd9Sstevel@tonic-gate         /*
2777c478bd9Sstevel@tonic-gate          * If the BufferField arguments have not been previously evaluated,
2787c478bd9Sstevel@tonic-gate          * evaluate them now and save the results.
2797c478bd9Sstevel@tonic-gate          */
2807c478bd9Sstevel@tonic-gate         if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
2817c478bd9Sstevel@tonic-gate         {
2827c478bd9Sstevel@tonic-gate             Status = AcpiDsGetBufferFieldArguments (ObjDesc);
2837c478bd9Sstevel@tonic-gate             if (ACPI_FAILURE (Status))
2847c478bd9Sstevel@tonic-gate             {
2857c478bd9Sstevel@tonic-gate                 return_ACPI_STATUS (Status);
2867c478bd9Sstevel@tonic-gate             }
2877c478bd9Sstevel@tonic-gate         }
2887c478bd9Sstevel@tonic-gate     }
289aa2aa9a6SDana Myers     else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
29057190917SDana Myers              (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS ||
2917b1019a6SJerry Jelinek               ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS ||
29257190917SDana Myers               ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI))
2937c478bd9Sstevel@tonic-gate     {
2947c478bd9Sstevel@tonic-gate         /*
2957b1019a6SJerry Jelinek          * This is an SMBus, GSBus or IPMI read. We must create a buffer to
2967b1019a6SJerry Jelinek          * hold the data and then directly access the region handler.
29757190917SDana Myers          *
2987b1019a6SJerry Jelinek          * Note: SMBus and GSBus protocol value is passed in upper 16-bits
2997b1019a6SJerry Jelinek          * of Function
3007c478bd9Sstevel@tonic-gate          */
3017b1019a6SJerry Jelinek         if (ObjDesc->Field.RegionObj->Region.SpaceId ==
3027b1019a6SJerry Jelinek             ACPI_ADR_SPACE_SMBUS)
30357190917SDana Myers         {
30457190917SDana Myers             Length = ACPI_SMBUS_BUFFER_SIZE;
30557190917SDana Myers             Function = ACPI_READ | (ObjDesc->Field.Attribute << 16);
30657190917SDana Myers         }
3077b1019a6SJerry Jelinek         else if (ObjDesc->Field.RegionObj->Region.SpaceId ==
3087b1019a6SJerry Jelinek             ACPI_ADR_SPACE_GSBUS)
3097b1019a6SJerry Jelinek         {
3107b1019a6SJerry Jelinek             AccessorType = ObjDesc->Field.Attribute;
3117b1019a6SJerry Jelinek             Length = AcpiExGetSerialAccessLength (
3127b1019a6SJerry Jelinek                 AccessorType, ObjDesc->Field.AccessLength);
3137b1019a6SJerry Jelinek 
3147b1019a6SJerry Jelinek             /*
3157b1019a6SJerry Jelinek              * Add additional 2 bytes for the GenericSerialBus data buffer:
3167b1019a6SJerry Jelinek              *
3177b1019a6SJerry Jelinek              *     Status;    (Byte 0 of the data buffer)
3187b1019a6SJerry Jelinek              *     Length;    (Byte 1 of the data buffer)
3197b1019a6SJerry Jelinek              *     Data[x-1]: (Bytes 2-x of the arbitrary length data buffer)
3207b1019a6SJerry Jelinek              */
3217b1019a6SJerry Jelinek             Length += 2;
3227b1019a6SJerry Jelinek             Function = ACPI_READ | (AccessorType << 16);
3237b1019a6SJerry Jelinek         }
32457190917SDana Myers         else /* IPMI */
32557190917SDana Myers         {
32657190917SDana Myers             Length = ACPI_IPMI_BUFFER_SIZE;
32757190917SDana Myers             Function = ACPI_READ;
32857190917SDana Myers         }
32957190917SDana Myers 
33057190917SDana Myers         BufferDesc = AcpiUtCreateBufferObject (Length);
3317c478bd9Sstevel@tonic-gate         if (!BufferDesc)
3327c478bd9Sstevel@tonic-gate         {
3337c478bd9Sstevel@tonic-gate             return_ACPI_STATUS (AE_NO_MEMORY);
3347c478bd9Sstevel@tonic-gate         }
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate         /* Lock entire transaction if requested */
3377c478bd9Sstevel@tonic-gate 
338db2bae30SDana Myers         AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
3397c478bd9Sstevel@tonic-gate 
34057190917SDana Myers         /* Call the region handler for the read */
34157190917SDana Myers 
3427c478bd9Sstevel@tonic-gate         Status = AcpiExAccessRegion (ObjDesc, 0,
3437b1019a6SJerry Jelinek             ACPI_CAST_PTR (UINT64, BufferDesc->Buffer.Pointer), Function);
3447b1019a6SJerry Jelinek 
345db2bae30SDana Myers         AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
3467c478bd9Sstevel@tonic-gate         goto Exit;
3477c478bd9Sstevel@tonic-gate     }
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate     /*
3507c478bd9Sstevel@tonic-gate      * Allocate a buffer for the contents of the field.
3517c478bd9Sstevel@tonic-gate      *
35226f3cdf0SGordon Ross      * If the field is larger than the current integer width, create
3537b1019a6SJerry Jelinek      * a BUFFER to hold it. Otherwise, use an INTEGER. This allows
3547c478bd9Sstevel@tonic-gate      * the use of arithmetic operators on the returned value if the
3557c478bd9Sstevel@tonic-gate      * field size is equal or smaller than an Integer.
3567c478bd9Sstevel@tonic-gate      *
3577c478bd9Sstevel@tonic-gate      * Note: Field.length is in bits.
3587c478bd9Sstevel@tonic-gate      */
3597b1019a6SJerry Jelinek     Length = (ACPI_SIZE) ACPI_ROUND_BITS_UP_TO_BYTES (
3607b1019a6SJerry Jelinek         ObjDesc->Field.BitLength);
3617b1019a6SJerry Jelinek 
3627c478bd9Sstevel@tonic-gate     if (Length > AcpiGbl_IntegerByteWidth)
3637c478bd9Sstevel@tonic-gate     {
3647c478bd9Sstevel@tonic-gate         /* Field is too large for an Integer, create a Buffer instead */
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate         BufferDesc = AcpiUtCreateBufferObject (Length);
3677c478bd9Sstevel@tonic-gate         if (!BufferDesc)
3687c478bd9Sstevel@tonic-gate         {
3697c478bd9Sstevel@tonic-gate             return_ACPI_STATUS (AE_NO_MEMORY);
3707c478bd9Sstevel@tonic-gate         }
3717c478bd9Sstevel@tonic-gate         Buffer = BufferDesc->Buffer.Pointer;
3727c478bd9Sstevel@tonic-gate     }
3737c478bd9Sstevel@tonic-gate     else
3747c478bd9Sstevel@tonic-gate     {
3757c478bd9Sstevel@tonic-gate         /* Field will fit within an Integer (normal case) */
3767c478bd9Sstevel@tonic-gate 
37757190917SDana Myers         BufferDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
3787c478bd9Sstevel@tonic-gate         if (!BufferDesc)
3797c478bd9Sstevel@tonic-gate         {
3807c478bd9Sstevel@tonic-gate             return_ACPI_STATUS (AE_NO_MEMORY);
3817c478bd9Sstevel@tonic-gate         }
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate         Length = AcpiGbl_IntegerByteWidth;
3847c478bd9Sstevel@tonic-gate         Buffer = &BufferDesc->Integer.Value;
3857c478bd9Sstevel@tonic-gate     }
3867c478bd9Sstevel@tonic-gate 
3877b1019a6SJerry Jelinek     if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
3887b1019a6SJerry Jelinek         (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO))
3897b1019a6SJerry Jelinek     {
3907b1019a6SJerry Jelinek         /*
3917b1019a6SJerry Jelinek          * For GPIO (GeneralPurposeIo), the Address will be the bit offset
3927b1019a6SJerry Jelinek          * from the previous Connection() operator, making it effectively a
3937b1019a6SJerry Jelinek          * pin number index. The BitLength is the length of the field, which
3947b1019a6SJerry Jelinek          * is thus the number of pins.
3957b1019a6SJerry Jelinek          */
3967b1019a6SJerry Jelinek         ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
3977b1019a6SJerry Jelinek             "GPIO FieldRead [FROM]:  Pin %u Bits %u\n",
3987b1019a6SJerry Jelinek             ObjDesc->Field.PinNumberIndex, ObjDesc->Field.BitLength));
3997b1019a6SJerry Jelinek 
4007b1019a6SJerry Jelinek         /* Lock entire transaction if requested */
4017b1019a6SJerry Jelinek 
4027b1019a6SJerry Jelinek         AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
4037b1019a6SJerry Jelinek 
4047b1019a6SJerry Jelinek         /* Perform the write */
4057b1019a6SJerry Jelinek 
4067b1019a6SJerry Jelinek         Status = AcpiExAccessRegion (
4077b1019a6SJerry Jelinek             ObjDesc, 0, (UINT64 *) Buffer, ACPI_READ);
4087b1019a6SJerry Jelinek 
4097b1019a6SJerry Jelinek         AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
4107b1019a6SJerry Jelinek         if (ACPI_FAILURE (Status))
4117b1019a6SJerry Jelinek         {
4127b1019a6SJerry Jelinek             AcpiUtRemoveReference (BufferDesc);
4137b1019a6SJerry Jelinek         }
4147b1019a6SJerry Jelinek         else
4157b1019a6SJerry Jelinek         {
4167b1019a6SJerry Jelinek             *RetBufferDesc = BufferDesc;
4177b1019a6SJerry Jelinek         }
4187b1019a6SJerry Jelinek         return_ACPI_STATUS (Status);
4197b1019a6SJerry Jelinek     }
4207b1019a6SJerry Jelinek 
4217c478bd9Sstevel@tonic-gate     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
4227c478bd9Sstevel@tonic-gate         "FieldRead [TO]:   Obj %p, Type %X, Buf %p, ByteLen %X\n",
423aa2aa9a6SDana Myers         ObjDesc, ObjDesc->Common.Type, Buffer, (UINT32) Length));
4247c478bd9Sstevel@tonic-gate     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
4257c478bd9Sstevel@tonic-gate         "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n",
4267c478bd9Sstevel@tonic-gate         ObjDesc->CommonField.BitLength,
4277c478bd9Sstevel@tonic-gate         ObjDesc->CommonField.StartFieldBitOffset,
4287c478bd9Sstevel@tonic-gate         ObjDesc->CommonField.BaseByteOffset));
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate     /* Lock entire transaction if requested */
4317c478bd9Sstevel@tonic-gate 
432db2bae30SDana Myers     AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate     /* Read from the field */
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate     Status = AcpiExExtractFromField (ObjDesc, Buffer, (UINT32) Length);
437db2bae30SDana Myers     AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate Exit:
4417c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
4427c478bd9Sstevel@tonic-gate     {
4437c478bd9Sstevel@tonic-gate         AcpiUtRemoveReference (BufferDesc);
4447c478bd9Sstevel@tonic-gate     }
445450d6964Smyers     else
4467c478bd9Sstevel@tonic-gate     {
4477c478bd9Sstevel@tonic-gate         *RetBufferDesc = BufferDesc;
4487c478bd9Sstevel@tonic-gate     }
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
4517c478bd9Sstevel@tonic-gate }
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate /*******************************************************************************
4557c478bd9Sstevel@tonic-gate  *
4567c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiExWriteDataToField
4577c478bd9Sstevel@tonic-gate  *
4587c478bd9Sstevel@tonic-gate  * PARAMETERS:  SourceDesc          - Contains data to write
4597c478bd9Sstevel@tonic-gate  *              ObjDesc             - The named field
4607c478bd9Sstevel@tonic-gate  *              ResultDesc          - Where the return value is returned, if any
4617c478bd9Sstevel@tonic-gate  *
4627c478bd9Sstevel@tonic-gate  * RETURN:      Status
4637c478bd9Sstevel@tonic-gate  *
4647c478bd9Sstevel@tonic-gate  * DESCRIPTION: Write to a named field
4657c478bd9Sstevel@tonic-gate  *
4667c478bd9Sstevel@tonic-gate  ******************************************************************************/
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiExWriteDataToField(ACPI_OPERAND_OBJECT * SourceDesc,ACPI_OPERAND_OBJECT * ObjDesc,ACPI_OPERAND_OBJECT ** ResultDesc)4697c478bd9Sstevel@tonic-gate AcpiExWriteDataToField (
4707c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     *SourceDesc,
4717c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     *ObjDesc,
4727c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     **ResultDesc)
4737c478bd9Sstevel@tonic-gate {
4747c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
4757c478bd9Sstevel@tonic-gate     UINT32                  Length;
4767c478bd9Sstevel@tonic-gate     void                    *Buffer;
4777c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     *BufferDesc;
47857190917SDana Myers     UINT32                  Function;
4797b1019a6SJerry Jelinek     UINT16                  AccessorType;
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate 
48227f7c583Smyers     ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField, ObjDesc);
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate     /* Parameter validation */
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate     if (!SourceDesc || !ObjDesc)
4887c478bd9Sstevel@tonic-gate     {
4897c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (AE_AML_NO_OPERAND);
4907c478bd9Sstevel@tonic-gate     }
4917c478bd9Sstevel@tonic-gate 
492aa2aa9a6SDana Myers     if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
4937c478bd9Sstevel@tonic-gate     {
4947c478bd9Sstevel@tonic-gate         /*
4957c478bd9Sstevel@tonic-gate          * If the BufferField arguments have not been previously evaluated,
4967c478bd9Sstevel@tonic-gate          * evaluate them now and save the results.
4977c478bd9Sstevel@tonic-gate          */
4987c478bd9Sstevel@tonic-gate         if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
4997c478bd9Sstevel@tonic-gate         {
5007c478bd9Sstevel@tonic-gate             Status = AcpiDsGetBufferFieldArguments (ObjDesc);
5017c478bd9Sstevel@tonic-gate             if (ACPI_FAILURE (Status))
5027c478bd9Sstevel@tonic-gate             {
5037c478bd9Sstevel@tonic-gate                 return_ACPI_STATUS (Status);
5047c478bd9Sstevel@tonic-gate             }
5057c478bd9Sstevel@tonic-gate         }
5067c478bd9Sstevel@tonic-gate     }
507aa2aa9a6SDana Myers     else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
50857190917SDana Myers              (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS ||
5097b1019a6SJerry Jelinek               ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS ||
51057190917SDana Myers               ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI))
5117c478bd9Sstevel@tonic-gate     {
5127c478bd9Sstevel@tonic-gate         /*
5137b1019a6SJerry Jelinek          * This is an SMBus, GSBus or IPMI write. We will bypass the entire
5147b1019a6SJerry Jelinek          * field mechanism and handoff the buffer directly to the handler.
5157b1019a6SJerry Jelinek          * For these address spaces, the buffer is bi-directional; on a
5167b1019a6SJerry Jelinek          * write, return data is returned in the same buffer.
51757190917SDana Myers          *
51857190917SDana Myers          * Source must be a buffer of sufficient size:
5197b1019a6SJerry Jelinek          * ACPI_SMBUS_BUFFER_SIZE, ACPI_GSBUS_BUFFER_SIZE, or
5207b1019a6SJerry Jelinek          * ACPI_IPMI_BUFFER_SIZE.
5217c478bd9Sstevel@tonic-gate          *
5227b1019a6SJerry Jelinek          * Note: SMBus and GSBus protocol type is passed in upper 16-bits
5237b1019a6SJerry Jelinek          * of Function
5247c478bd9Sstevel@tonic-gate          */
525aa2aa9a6SDana Myers         if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER)
5267c478bd9Sstevel@tonic-gate         {
52757190917SDana Myers             ACPI_ERROR ((AE_INFO,
5287b1019a6SJerry Jelinek                 "SMBus/IPMI/GenericSerialBus write requires "
5297b1019a6SJerry Jelinek                 "Buffer, found type %s",
5307c478bd9Sstevel@tonic-gate                 AcpiUtGetObjectTypeName (SourceDesc)));
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
5337c478bd9Sstevel@tonic-gate         }
5347c478bd9Sstevel@tonic-gate 
5357b1019a6SJerry Jelinek         if (ObjDesc->Field.RegionObj->Region.SpaceId ==
5367b1019a6SJerry Jelinek             ACPI_ADR_SPACE_SMBUS)
53757190917SDana Myers         {
53857190917SDana Myers             Length = ACPI_SMBUS_BUFFER_SIZE;
53957190917SDana Myers             Function = ACPI_WRITE | (ObjDesc->Field.Attribute << 16);
54057190917SDana Myers         }
5417b1019a6SJerry Jelinek         else if (ObjDesc->Field.RegionObj->Region.SpaceId ==
5427b1019a6SJerry Jelinek             ACPI_ADR_SPACE_GSBUS)
5437b1019a6SJerry Jelinek         {
5447b1019a6SJerry Jelinek             AccessorType = ObjDesc->Field.Attribute;
5457b1019a6SJerry Jelinek             Length = AcpiExGetSerialAccessLength (
5467b1019a6SJerry Jelinek                 AccessorType, ObjDesc->Field.AccessLength);
5477b1019a6SJerry Jelinek 
5487b1019a6SJerry Jelinek             /*
5497b1019a6SJerry Jelinek              * Add additional 2 bytes for the GenericSerialBus data buffer:
5507b1019a6SJerry Jelinek              *
5517b1019a6SJerry Jelinek              *     Status;    (Byte 0 of the data buffer)
5527b1019a6SJerry Jelinek              *     Length;    (Byte 1 of the data buffer)
5537b1019a6SJerry Jelinek              *     Data[x-1]: (Bytes 2-x of the arbitrary length data buffer)
5547b1019a6SJerry Jelinek              */
5557b1019a6SJerry Jelinek             Length += 2;
5567b1019a6SJerry Jelinek             Function = ACPI_WRITE | (AccessorType << 16);
5577b1019a6SJerry Jelinek         }
55857190917SDana Myers         else /* IPMI */
55957190917SDana Myers         {
56057190917SDana Myers             Length = ACPI_IPMI_BUFFER_SIZE;
56157190917SDana Myers             Function = ACPI_WRITE;
56257190917SDana Myers         }
56357190917SDana Myers 
56457190917SDana Myers         if (SourceDesc->Buffer.Length < Length)
5657c478bd9Sstevel@tonic-gate         {
56630082d0cSmyers             ACPI_ERROR ((AE_INFO,
5677b1019a6SJerry Jelinek                 "SMBus/IPMI/GenericSerialBus write requires "
5687b1019a6SJerry Jelinek                 "Buffer of length %u, found length %u",
56957190917SDana Myers                 Length, SourceDesc->Buffer.Length));
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate             return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
5727c478bd9Sstevel@tonic-gate         }
5737c478bd9Sstevel@tonic-gate 
57457190917SDana Myers         /* Create the bi-directional buffer */
57557190917SDana Myers 
57657190917SDana Myers         BufferDesc = AcpiUtCreateBufferObject (Length);
5777c478bd9Sstevel@tonic-gate         if (!BufferDesc)
5787c478bd9Sstevel@tonic-gate         {
5797c478bd9Sstevel@tonic-gate             return_ACPI_STATUS (AE_NO_MEMORY);
5807c478bd9Sstevel@tonic-gate         }
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate         Buffer = BufferDesc->Buffer.Pointer;
5837b1019a6SJerry Jelinek         memcpy (Buffer, SourceDesc->Buffer.Pointer, Length);
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate         /* Lock entire transaction if requested */
5867c478bd9Sstevel@tonic-gate 
587db2bae30SDana Myers         AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate         /*
5907c478bd9Sstevel@tonic-gate          * Perform the write (returns status and perhaps data in the
5917c478bd9Sstevel@tonic-gate          * same buffer)
5927c478bd9Sstevel@tonic-gate          */
5937b1019a6SJerry Jelinek         Status = AcpiExAccessRegion (
5947b1019a6SJerry Jelinek             ObjDesc, 0, (UINT64 *) Buffer, Function);
595db2bae30SDana Myers         AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate         *ResultDesc = BufferDesc;
5987c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
5997c478bd9Sstevel@tonic-gate     }
6007b1019a6SJerry Jelinek     else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
6017b1019a6SJerry Jelinek              (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO))
6027b1019a6SJerry Jelinek     {
6037b1019a6SJerry Jelinek         /*
6047b1019a6SJerry Jelinek          * For GPIO (GeneralPurposeIo), we will bypass the entire field
6057b1019a6SJerry Jelinek          * mechanism and handoff the bit address and bit width directly to
6067b1019a6SJerry Jelinek          * the handler. The Address will be the bit offset
6077b1019a6SJerry Jelinek          * from the previous Connection() operator, making it effectively a
6087b1019a6SJerry Jelinek          * pin number index. The BitLength is the length of the field, which
6097b1019a6SJerry Jelinek          * is thus the number of pins.
6107b1019a6SJerry Jelinek          */
6117b1019a6SJerry Jelinek         if (SourceDesc->Common.Type != ACPI_TYPE_INTEGER)
6127b1019a6SJerry Jelinek         {
6137b1019a6SJerry Jelinek             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
6147b1019a6SJerry Jelinek         }
6157b1019a6SJerry Jelinek 
6167b1019a6SJerry Jelinek         ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
6177b1019a6SJerry Jelinek             "GPIO FieldWrite [FROM]: (%s:%X), Val %.8X  [TO]: Pin %u Bits %u\n",
6187b1019a6SJerry Jelinek             AcpiUtGetTypeName (SourceDesc->Common.Type),
6197b1019a6SJerry Jelinek             SourceDesc->Common.Type, (UINT32) SourceDesc->Integer.Value,
6207b1019a6SJerry Jelinek             ObjDesc->Field.PinNumberIndex, ObjDesc->Field.BitLength));
6217b1019a6SJerry Jelinek 
6227b1019a6SJerry Jelinek         Buffer = &SourceDesc->Integer.Value;
6237b1019a6SJerry Jelinek 
6247b1019a6SJerry Jelinek         /* Lock entire transaction if requested */
6257b1019a6SJerry Jelinek 
6267b1019a6SJerry Jelinek         AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
6277b1019a6SJerry Jelinek 
6287b1019a6SJerry Jelinek         /* Perform the write */
6297b1019a6SJerry Jelinek 
6307b1019a6SJerry Jelinek         Status = AcpiExAccessRegion (
6317b1019a6SJerry Jelinek             ObjDesc, 0, (UINT64 *) Buffer, ACPI_WRITE);
6327b1019a6SJerry Jelinek         AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
6337b1019a6SJerry Jelinek         return_ACPI_STATUS (Status);
6347b1019a6SJerry Jelinek     }
6357c478bd9Sstevel@tonic-gate 
6367c478bd9Sstevel@tonic-gate     /* Get a pointer to the data to be written */
6377c478bd9Sstevel@tonic-gate 
638aa2aa9a6SDana Myers     switch (SourceDesc->Common.Type)
6397c478bd9Sstevel@tonic-gate     {
6407c478bd9Sstevel@tonic-gate     case ACPI_TYPE_INTEGER:
6417b1019a6SJerry Jelinek 
6427c478bd9Sstevel@tonic-gate         Buffer = &SourceDesc->Integer.Value;
6437c478bd9Sstevel@tonic-gate         Length = sizeof (SourceDesc->Integer.Value);
6447c478bd9Sstevel@tonic-gate         break;
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate     case ACPI_TYPE_BUFFER:
6477b1019a6SJerry Jelinek 
6487c478bd9Sstevel@tonic-gate         Buffer = SourceDesc->Buffer.Pointer;
6497c478bd9Sstevel@tonic-gate         Length = SourceDesc->Buffer.Length;
6507c478bd9Sstevel@tonic-gate         break;
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate     case ACPI_TYPE_STRING:
6537b1019a6SJerry Jelinek 
6547c478bd9Sstevel@tonic-gate         Buffer = SourceDesc->String.Pointer;
6557c478bd9Sstevel@tonic-gate         Length = SourceDesc->String.Length;
6567c478bd9Sstevel@tonic-gate         break;
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate     default:
6597b1019a6SJerry Jelinek 
6607c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
6617c478bd9Sstevel@tonic-gate     }
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
6647c478bd9Sstevel@tonic-gate         "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
665aa2aa9a6SDana Myers         SourceDesc, AcpiUtGetTypeName (SourceDesc->Common.Type),
666aa2aa9a6SDana Myers         SourceDesc->Common.Type, Buffer, Length));
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
6697c478bd9Sstevel@tonic-gate         "FieldWrite [TO]:   Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n",
670aa2aa9a6SDana Myers         ObjDesc, AcpiUtGetTypeName (ObjDesc->Common.Type),
671aa2aa9a6SDana Myers         ObjDesc->Common.Type,
6727c478bd9Sstevel@tonic-gate         ObjDesc->CommonField.BitLength,
6737c478bd9Sstevel@tonic-gate         ObjDesc->CommonField.StartFieldBitOffset,
6747c478bd9Sstevel@tonic-gate         ObjDesc->CommonField.BaseByteOffset));
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate     /* Lock entire transaction if requested */
6777c478bd9Sstevel@tonic-gate 
678db2bae30SDana Myers     AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate     /* Write to the field */
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate     Status = AcpiExInsertIntoField (ObjDesc, Buffer, Length);
683db2bae30SDana Myers     AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
6867c478bd9Sstevel@tonic-gate }
687