Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:02

0001 /******************************************************************************
0002  *
0003  * Module Name: exserial - FieldUnit support for serial address spaces
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights. You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code. No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision. In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change. Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee. Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution. In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government. In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************
0115  *
0116  * Alternatively, you may choose to be licensed under the terms of the
0117  * following license:
0118  *
0119  * Redistribution and use in source and binary forms, with or without
0120  * modification, are permitted provided that the following conditions
0121  * are met:
0122  * 1. Redistributions of source code must retain the above copyright
0123  *    notice, this list of conditions, and the following disclaimer,
0124  *    without modification.
0125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0126  *    substantially similar to the "NO WARRANTY" disclaimer below
0127  *    ("Disclaimer") and any redistribution must be conditioned upon
0128  *    including a substantially similar Disclaimer requirement for further
0129  *    binary redistribution.
0130  * 3. Neither the names of the above-listed copyright holders nor the names
0131  *    of any contributors may be used to endorse or promote products derived
0132  *    from this software without specific prior written permission.
0133  *
0134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0145  *
0146  * Alternatively, you may choose to be licensed under the terms of the
0147  * GNU General Public License ("GPL") version 2 as published by the Free
0148  * Software Foundation.
0149  *
0150  *****************************************************************************/
0151 
0152 #include "acpi.h"
0153 #include "accommon.h"
0154 #include "acdispat.h"
0155 #include "acinterp.h"
0156 #include "amlcode.h"
0157 
0158 
0159 #define _COMPONENT          ACPI_EXECUTER
0160         ACPI_MODULE_NAME    ("exserial")
0161 
0162 
0163 /*******************************************************************************
0164  *
0165  * FUNCTION:    AcpiExReadGpio
0166  *
0167  * PARAMETERS:  ObjDesc             - The named field to read
0168  *              Buffer              - Where the return data is returned
0169  *
0170  * RETURN:      Status
0171  *
0172  * DESCRIPTION: Read from a named field that references a Generic Serial Bus
0173  *              field
0174  *
0175  ******************************************************************************/
0176 
0177 ACPI_STATUS
0178 AcpiExReadGpio (
0179     ACPI_OPERAND_OBJECT     *ObjDesc,
0180     void                    *Buffer)
0181 {
0182     ACPI_STATUS             Status;
0183 
0184 
0185     ACPI_FUNCTION_TRACE_PTR (ExReadGpio, ObjDesc);
0186 
0187 
0188     /*
0189      * For GPIO (GeneralPurposeIo), the Address will be the bit offset
0190      * from the previous Connection() operator, making it effectively a
0191      * pin number index. The BitLength is the length of the field, which
0192      * is thus the number of pins.
0193      */
0194     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
0195         "GPIO FieldRead [FROM]:  Pin %u Bits %u\n",
0196         ObjDesc->Field.PinNumberIndex, ObjDesc->Field.BitLength));
0197 
0198     /* Lock entire transaction if requested */
0199 
0200     AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
0201 
0202     /* Perform the read */
0203 
0204     Status = AcpiExAccessRegion (
0205         ObjDesc, 0, (UINT64 *) Buffer, ACPI_READ);
0206 
0207     AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
0208     return_ACPI_STATUS (Status);
0209 }
0210 
0211 
0212 /*******************************************************************************
0213  *
0214  * FUNCTION:    AcpiExWriteGpio
0215  *
0216  * PARAMETERS:  SourceDesc          - Contains data to write. Expect to be
0217  *                                    an Integer object.
0218  *              ObjDesc             - The named field
0219  *              ResultDesc          - Where the return value is returned, if any
0220  *
0221  * RETURN:      Status
0222  *
0223  * DESCRIPTION: Write to a named field that references a General Purpose I/O
0224  *              field.
0225  *
0226  ******************************************************************************/
0227 
0228 ACPI_STATUS
0229 AcpiExWriteGpio (
0230     ACPI_OPERAND_OBJECT     *SourceDesc,
0231     ACPI_OPERAND_OBJECT     *ObjDesc,
0232     ACPI_OPERAND_OBJECT     **ReturnBuffer)
0233 {
0234     ACPI_STATUS             Status;
0235     void                    *Buffer;
0236 
0237 
0238     ACPI_FUNCTION_TRACE_PTR (ExWriteGpio, ObjDesc);
0239 
0240 
0241     /*
0242      * For GPIO (GeneralPurposeIo), we will bypass the entire field
0243      * mechanism and handoff the bit address and bit width directly to
0244      * the handler. The Address will be the bit offset
0245      * from the previous Connection() operator, making it effectively a
0246      * pin number index. The BitLength is the length of the field, which
0247      * is thus the number of pins.
0248      */
0249     if (SourceDesc->Common.Type != ACPI_TYPE_INTEGER)
0250     {
0251         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
0252     }
0253 
0254     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
0255         "GPIO FieldWrite [FROM]: (%s:%X), Value %.8X  [TO]: Pin %u Bits %u\n",
0256         AcpiUtGetTypeName (SourceDesc->Common.Type),
0257         SourceDesc->Common.Type, (UINT32) SourceDesc->Integer.Value,
0258         ObjDesc->Field.PinNumberIndex, ObjDesc->Field.BitLength));
0259 
0260     Buffer = &SourceDesc->Integer.Value;
0261 
0262     /* Lock entire transaction if requested */
0263 
0264     AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
0265 
0266     /* Perform the write */
0267 
0268     Status = AcpiExAccessRegion (
0269         ObjDesc, 0, (UINT64 *) Buffer, ACPI_WRITE);
0270     AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
0271     return_ACPI_STATUS (Status);
0272 }
0273 
0274 
0275 /*******************************************************************************
0276  *
0277  * FUNCTION:    AcpiExReadSerialBus
0278  *
0279  * PARAMETERS:  ObjDesc             - The named field to read
0280  *              ReturnBuffer        - Where the return value is returned, if any
0281  *
0282  * RETURN:      Status
0283  *
0284  * DESCRIPTION: Read from a named field that references a serial bus
0285  *              (SMBus, IPMI, or GSBus).
0286  *
0287  ******************************************************************************/
0288 
0289 ACPI_STATUS
0290 AcpiExReadSerialBus (
0291     ACPI_OPERAND_OBJECT     *ObjDesc,
0292     ACPI_OPERAND_OBJECT     **ReturnBuffer)
0293 {
0294     ACPI_STATUS             Status;
0295     UINT32                  BufferLength;
0296     ACPI_OPERAND_OBJECT     *BufferDesc;
0297     UINT32                  Function;
0298     UINT16                  AccessorType;
0299 
0300 
0301     ACPI_FUNCTION_TRACE_PTR (ExReadSerialBus, ObjDesc);
0302 
0303 
0304     /*
0305      * This is an SMBus, GSBus or IPMI read. We must create a buffer to
0306      * hold the data and then directly access the region handler.
0307      *
0308      * Note: SMBus and GSBus protocol value is passed in upper 16-bits
0309      * of Function
0310      *
0311      * Common buffer format:
0312      *     Status;    (Byte 0 of the data buffer)
0313      *     Length;    (Byte 1 of the data buffer)
0314      *     Data[x-1]: (Bytes 2-x of the arbitrary length data buffer)
0315      */
0316     switch (ObjDesc->Field.RegionObj->Region.SpaceId)
0317     {
0318     case ACPI_ADR_SPACE_SMBUS:
0319 
0320         BufferLength = ACPI_SMBUS_BUFFER_SIZE;
0321         Function = ACPI_READ | (ObjDesc->Field.Attribute << 16);
0322         break;
0323 
0324     case ACPI_ADR_SPACE_IPMI:
0325 
0326         BufferLength = ACPI_IPMI_BUFFER_SIZE;
0327         Function = ACPI_READ;
0328         break;
0329 
0330     case ACPI_ADR_SPACE_GSBUS:
0331 
0332         AccessorType = ObjDesc->Field.Attribute;
0333         if (AccessorType == AML_FIELD_ATTRIB_RAW_PROCESS_BYTES)
0334         {
0335             ACPI_ERROR ((AE_INFO,
0336                 "Invalid direct read using bidirectional write-then-read protocol"));
0337 
0338             return_ACPI_STATUS (AE_AML_PROTOCOL);
0339         }
0340 
0341         Status = AcpiExGetProtocolBufferLength (AccessorType, &BufferLength);
0342         if (ACPI_FAILURE (Status))
0343         {
0344             ACPI_ERROR ((AE_INFO,
0345                 "Invalid protocol ID for GSBus: 0x%4.4X", AccessorType));
0346 
0347             return_ACPI_STATUS (Status);
0348         }
0349 
0350         /* Add header length to get the full size of the buffer */
0351 
0352         BufferLength += ACPI_SERIAL_HEADER_SIZE;
0353         Function = ACPI_READ | (AccessorType << 16);
0354         break;
0355 
0356     case ACPI_ADR_SPACE_PLATFORM_RT:
0357 
0358         BufferLength = ACPI_PRM_INPUT_BUFFER_SIZE;
0359         Function = ACPI_READ;
0360         break;
0361 
0362     default:
0363         return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID);
0364     }
0365 
0366     /* Create the local transfer buffer that is returned to the caller */
0367 
0368     BufferDesc = AcpiUtCreateBufferObject (BufferLength);
0369     if (!BufferDesc)
0370     {
0371         return_ACPI_STATUS (AE_NO_MEMORY);
0372     }
0373 
0374     /* Lock entire transaction if requested */
0375 
0376     AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
0377 
0378     /* Call the region handler for the write-then-read */
0379 
0380     Status = AcpiExAccessRegion (ObjDesc, 0,
0381         ACPI_CAST_PTR (UINT64, BufferDesc->Buffer.Pointer), Function);
0382     AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
0383 
0384     *ReturnBuffer = BufferDesc;
0385     return_ACPI_STATUS (Status);
0386 }
0387 
0388 
0389 /*******************************************************************************
0390  *
0391  * FUNCTION:    AcpiExWriteSerialBus
0392  *
0393  * PARAMETERS:  SourceDesc          - Contains data to write
0394  *              ObjDesc             - The named field
0395  *              ReturnBuffer        - Where the return value is returned, if any
0396  *
0397  * RETURN:      Status
0398  *
0399  * DESCRIPTION: Write to a named field that references a serial bus
0400  *              (SMBus, IPMI, GSBus).
0401  *
0402  ******************************************************************************/
0403 
0404 ACPI_STATUS
0405 AcpiExWriteSerialBus (
0406     ACPI_OPERAND_OBJECT     *SourceDesc,
0407     ACPI_OPERAND_OBJECT     *ObjDesc,
0408     ACPI_OPERAND_OBJECT     **ReturnBuffer)
0409 {
0410     ACPI_STATUS             Status;
0411     UINT32                  BufferLength;
0412     UINT32                  DataLength;
0413     void                    *Buffer;
0414     ACPI_OPERAND_OBJECT     *BufferDesc;
0415     UINT32                  Function;
0416     UINT16                  AccessorType;
0417 
0418 
0419     ACPI_FUNCTION_TRACE_PTR (ExWriteSerialBus, ObjDesc);
0420 
0421 
0422     /*
0423      * This is an SMBus, GSBus or IPMI write. We will bypass the entire
0424      * field mechanism and handoff the buffer directly to the handler.
0425      * For these address spaces, the buffer is bidirectional; on a
0426      * write, return data is returned in the same buffer.
0427      *
0428      * Source must be a buffer of sufficient size, these are fixed size:
0429      * ACPI_SMBUS_BUFFER_SIZE, or ACPI_IPMI_BUFFER_SIZE.
0430      *
0431      * Note: SMBus and GSBus protocol type is passed in upper 16-bits
0432      * of Function
0433      *
0434      * Common buffer format:
0435      *     Status;    (Byte 0 of the data buffer)
0436      *     Length;    (Byte 1 of the data buffer)
0437      *     Data[x-1]: (Bytes 2-x of the arbitrary length data buffer)
0438      */
0439     if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER)
0440     {
0441         ACPI_ERROR ((AE_INFO,
0442             "SMBus/IPMI/GenericSerialBus write requires "
0443             "Buffer, found type %s",
0444             AcpiUtGetObjectTypeName (SourceDesc)));
0445 
0446         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
0447     }
0448 
0449     switch (ObjDesc->Field.RegionObj->Region.SpaceId)
0450     {
0451     case ACPI_ADR_SPACE_SMBUS:
0452 
0453         BufferLength = ACPI_SMBUS_BUFFER_SIZE;
0454         Function = ACPI_WRITE | (ObjDesc->Field.Attribute << 16);
0455         break;
0456 
0457     case ACPI_ADR_SPACE_IPMI:
0458 
0459         BufferLength = ACPI_IPMI_BUFFER_SIZE;
0460         Function = ACPI_WRITE;
0461         break;
0462 
0463     case ACPI_ADR_SPACE_GSBUS:
0464 
0465         AccessorType = ObjDesc->Field.Attribute;
0466         Status = AcpiExGetProtocolBufferLength (AccessorType, &BufferLength);
0467         if (ACPI_FAILURE (Status))
0468         {
0469             ACPI_ERROR ((AE_INFO,
0470                 "Invalid protocol ID for GSBus: 0x%4.4X", AccessorType));
0471 
0472             return_ACPI_STATUS (Status);
0473         }
0474 
0475         /* Add header length to get the full size of the buffer */
0476 
0477         BufferLength += ACPI_SERIAL_HEADER_SIZE;
0478         Function = ACPI_WRITE | (AccessorType << 16);
0479         break;
0480 
0481     case ACPI_ADR_SPACE_PLATFORM_RT:
0482 
0483         BufferLength = ACPI_PRM_INPUT_BUFFER_SIZE;
0484         Function = ACPI_WRITE;
0485         break;
0486 
0487     case ACPI_ADR_SPACE_FIXED_HARDWARE:
0488 
0489         BufferLength = ACPI_FFH_INPUT_BUFFER_SIZE;
0490         Function = ACPI_WRITE;
0491         break;
0492 
0493     default:
0494         return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID);
0495     }
0496 
0497     /* Create the transfer/bidirectional/return buffer */
0498 
0499     BufferDesc = AcpiUtCreateBufferObject (BufferLength);
0500     if (!BufferDesc)
0501     {
0502         return_ACPI_STATUS (AE_NO_MEMORY);
0503     }
0504 
0505     /* Copy the input buffer data to the transfer buffer */
0506 
0507     Buffer = BufferDesc->Buffer.Pointer;
0508     DataLength = ACPI_MIN (BufferLength, SourceDesc->Buffer.Length);
0509     memcpy (Buffer, SourceDesc->Buffer.Pointer, DataLength);
0510 
0511     /* Lock entire transaction if requested */
0512 
0513     AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
0514 
0515     /*
0516      * Perform the write (returns status and perhaps data in the
0517      * same buffer)
0518      */
0519     Status = AcpiExAccessRegion (
0520         ObjDesc, 0, (UINT64 *) Buffer, Function);
0521     AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
0522 
0523     *ReturnBuffer = BufferDesc;
0524     return_ACPI_STATUS (Status);
0525 }