Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenexfield.c
Go to the documentation of this file.
00001 /****************************************************************************** 00002 * 00003 * Module Name: exfield - ACPI AML (p-code) execution - field manipulation 00004 * 00005 *****************************************************************************/ 00006 00007 /****************************************************************************** 00008 * 00009 * 1. Copyright Notice 00010 * 00011 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp. 00012 * All rights reserved. 00013 * 00014 * 2. License 00015 * 00016 * 2.1. This is your license from Intel Corp. under its intellectual property 00017 * rights. You may have additional license terms from the party that provided 00018 * you this software, covering your right to use that party's intellectual 00019 * property rights. 00020 * 00021 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 00022 * copy of the source code appearing in this file ("Covered Code") an 00023 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 00024 * base code distributed originally by Intel ("Original Intel Code") to copy, 00025 * make derivatives, distribute, use and display any portion of the Covered 00026 * Code in any form, with the right to sublicense such rights; and 00027 * 00028 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 00029 * license (with the right to sublicense), under only those claims of Intel 00030 * patents that are infringed by the Original Intel Code, to make, use, sell, 00031 * offer to sell, and import the Covered Code and derivative works thereof 00032 * solely to the minimum extent necessary to exercise the above copyright 00033 * license, and in no event shall the patent license extend to any additions 00034 * to or modifications of the Original Intel Code. No other license or right 00035 * is granted directly or by implication, estoppel or otherwise; 00036 * 00037 * The above copyright and patent license is granted only if the following 00038 * conditions are met: 00039 * 00040 * 3. Conditions 00041 * 00042 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 00043 * Redistribution of source code of any substantial portion of the Covered 00044 * Code or modification with rights to further distribute source must include 00045 * the above Copyright Notice, the above License, this list of Conditions, 00046 * and the following Disclaimer and Export Compliance provision. In addition, 00047 * Licensee must cause all Covered Code to which Licensee contributes to 00048 * contain a file documenting the changes Licensee made to create that Covered 00049 * Code and the date of any change. Licensee must include in that file the 00050 * documentation of any changes made by any predecessor Licensee. Licensee 00051 * must include a prominent statement that the modification is derived, 00052 * directly or indirectly, from Original Intel Code. 00053 * 00054 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 00055 * Redistribution of source code of any substantial portion of the Covered 00056 * Code or modification without rights to further distribute source must 00057 * include the following Disclaimer and Export Compliance provision in the 00058 * documentation and/or other materials provided with distribution. In 00059 * addition, Licensee may not authorize further sublicense of source of any 00060 * portion of the Covered Code, and must include terms to the effect that the 00061 * license from Licensee to its licensee is limited to the intellectual 00062 * property embodied in the software Licensee provides to its licensee, and 00063 * not to intellectual property embodied in modifications its licensee may 00064 * make. 00065 * 00066 * 3.3. Redistribution of Executable. Redistribution in executable form of any 00067 * substantial portion of the Covered Code or modification must reproduce the 00068 * above Copyright Notice, and the following Disclaimer and Export Compliance 00069 * provision in the documentation and/or other materials provided with the 00070 * distribution. 00071 * 00072 * 3.4. Intel retains all right, title, and interest in and to the Original 00073 * Intel Code. 00074 * 00075 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 00076 * Intel shall be used in advertising or otherwise to promote the sale, use or 00077 * other dealings in products derived from or relating to the Covered Code 00078 * without prior written authorization from Intel. 00079 * 00080 * 4. Disclaimer and Export Compliance 00081 * 00082 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 00083 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 00084 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 00085 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 00086 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 00087 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 00088 * PARTICULAR PURPOSE. 00089 * 00090 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 00091 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 00092 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 00093 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 00094 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 00095 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 00096 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 00097 * LIMITED REMEDY. 00098 * 00099 * 4.3. Licensee shall not export, either directly or indirectly, any of this 00100 * software or system incorporating such software without first obtaining any 00101 * required license or other approval from the U. S. Department of Commerce or 00102 * any other agency or department of the United States Government. In the 00103 * event Licensee exports any such software from the United States or 00104 * re-exports any such software from a foreign destination, Licensee shall 00105 * ensure that the distribution and export/re-export of the software is in 00106 * compliance with all laws, regulations, orders, or other restrictions of the 00107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 00108 * any of its subsidiaries will export/re-export any technical data, process, 00109 * software, or service, directly or indirectly, to any country for which the 00110 * United States government or any agency thereof requires an export license, 00111 * other governmental approval, or letter of assurance, without first obtaining 00112 * such license, approval or letter. 00113 * 00114 *****************************************************************************/ 00115 00116 00117 #define __EXFIELD_C__ 00118 00119 #include "acpi.h" 00120 #include "accommon.h" 00121 #include "acdispat.h" 00122 #include "acinterp.h" 00123 00124 00125 #define _COMPONENT ACPI_EXECUTER 00126 ACPI_MODULE_NAME ("exfield") 00127 00128 00129 /******************************************************************************* 00130 * 00131 * FUNCTION: AcpiExReadDataFromField 00132 * 00133 * PARAMETERS: WalkState - Current execution state 00134 * ObjDesc - The named field 00135 * RetBufferDesc - Where the return data object is stored 00136 * 00137 * RETURN: Status 00138 * 00139 * DESCRIPTION: Read from a named field. Returns either an Integer or a 00140 * Buffer, depending on the size of the field. 00141 * 00142 ******************************************************************************/ 00143 00144 ACPI_STATUS 00145 AcpiExReadDataFromField ( 00146 ACPI_WALK_STATE *WalkState, 00147 ACPI_OPERAND_OBJECT *ObjDesc, 00148 ACPI_OPERAND_OBJECT **RetBufferDesc) 00149 { 00150 ACPI_STATUS Status; 00151 ACPI_OPERAND_OBJECT *BufferDesc; 00152 ACPI_SIZE Length; 00153 void *Buffer; 00154 UINT32 Function; 00155 00156 00157 ACPI_FUNCTION_TRACE_PTR (ExReadDataFromField, ObjDesc); 00158 00159 00160 /* Parameter validation */ 00161 00162 if (!ObjDesc) 00163 { 00164 return_ACPI_STATUS (AE_AML_NO_OPERAND); 00165 } 00166 if (!RetBufferDesc) 00167 { 00168 return_ACPI_STATUS (AE_BAD_PARAMETER); 00169 } 00170 00171 if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD) 00172 { 00173 /* 00174 * If the BufferField arguments have not been previously evaluated, 00175 * evaluate them now and save the results. 00176 */ 00177 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)) 00178 { 00179 Status = AcpiDsGetBufferFieldArguments (ObjDesc); 00180 if (ACPI_FAILURE (Status)) 00181 { 00182 return_ACPI_STATUS (Status); 00183 } 00184 } 00185 } 00186 else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) && 00187 (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS || 00188 ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI)) 00189 { 00190 /* 00191 * This is an SMBus or IPMI read. We must create a buffer to hold 00192 * the data and then directly access the region handler. 00193 * 00194 * Note: Smbus protocol value is passed in upper 16-bits of Function 00195 */ 00196 if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS) 00197 { 00198 Length = ACPI_SMBUS_BUFFER_SIZE; 00199 Function = ACPI_READ | (ObjDesc->Field.Attribute << 16); 00200 } 00201 else /* IPMI */ 00202 { 00203 Length = ACPI_IPMI_BUFFER_SIZE; 00204 Function = ACPI_READ; 00205 } 00206 00207 BufferDesc = AcpiUtCreateBufferObject (Length); 00208 if (!BufferDesc) 00209 { 00210 return_ACPI_STATUS (AE_NO_MEMORY); 00211 } 00212 00213 /* Lock entire transaction if requested */ 00214 00215 AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags); 00216 00217 /* Call the region handler for the read */ 00218 00219 Status = AcpiExAccessRegion (ObjDesc, 0, 00220 ACPI_CAST_PTR (UINT64, BufferDesc->Buffer.Pointer), 00221 Function); 00222 AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags); 00223 goto Exit; 00224 } 00225 00226 /* 00227 * Allocate a buffer for the contents of the field. 00228 * 00229 * If the field is larger than the current integer width, create 00230 * a BUFFER to hold it. Otherwise, use an INTEGER. This allows 00231 * the use of arithmetic operators on the returned value if the 00232 * field size is equal or smaller than an Integer. 00233 * 00234 * Note: Field.length is in bits. 00235 */ 00236 Length = (ACPI_SIZE) ACPI_ROUND_BITS_UP_TO_BYTES (ObjDesc->Field.BitLength); 00237 if (Length > AcpiGbl_IntegerByteWidth) 00238 { 00239 /* Field is too large for an Integer, create a Buffer instead */ 00240 00241 BufferDesc = AcpiUtCreateBufferObject (Length); 00242 if (!BufferDesc) 00243 { 00244 return_ACPI_STATUS (AE_NO_MEMORY); 00245 } 00246 Buffer = BufferDesc->Buffer.Pointer; 00247 } 00248 else 00249 { 00250 /* Field will fit within an Integer (normal case) */ 00251 00252 BufferDesc = AcpiUtCreateIntegerObject ((UINT64) 0); 00253 if (!BufferDesc) 00254 { 00255 return_ACPI_STATUS (AE_NO_MEMORY); 00256 } 00257 00258 Length = AcpiGbl_IntegerByteWidth; 00259 Buffer = &BufferDesc->Integer.Value; 00260 } 00261 00262 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 00263 "FieldRead [TO]: Obj %p, Type %X, Buf %p, ByteLen %X\n", 00264 ObjDesc, ObjDesc->Common.Type, Buffer, (UINT32) Length)); 00265 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 00266 "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n", 00267 ObjDesc->CommonField.BitLength, 00268 ObjDesc->CommonField.StartFieldBitOffset, 00269 ObjDesc->CommonField.BaseByteOffset)); 00270 00271 /* Lock entire transaction if requested */ 00272 00273 AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags); 00274 00275 /* Read from the field */ 00276 00277 Status = AcpiExExtractFromField (ObjDesc, Buffer, (UINT32) Length); 00278 AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags); 00279 00280 00281 Exit: 00282 if (ACPI_FAILURE (Status)) 00283 { 00284 AcpiUtRemoveReference (BufferDesc); 00285 } 00286 else 00287 { 00288 *RetBufferDesc = BufferDesc; 00289 } 00290 00291 return_ACPI_STATUS (Status); 00292 } 00293 00294 00295 /******************************************************************************* 00296 * 00297 * FUNCTION: AcpiExWriteDataToField 00298 * 00299 * PARAMETERS: SourceDesc - Contains data to write 00300 * ObjDesc - The named field 00301 * ResultDesc - Where the return value is returned, if any 00302 * 00303 * RETURN: Status 00304 * 00305 * DESCRIPTION: Write to a named field 00306 * 00307 ******************************************************************************/ 00308 00309 ACPI_STATUS 00310 AcpiExWriteDataToField ( 00311 ACPI_OPERAND_OBJECT *SourceDesc, 00312 ACPI_OPERAND_OBJECT *ObjDesc, 00313 ACPI_OPERAND_OBJECT **ResultDesc) 00314 { 00315 ACPI_STATUS Status; 00316 UINT32 Length; 00317 void *Buffer; 00318 ACPI_OPERAND_OBJECT *BufferDesc; 00319 UINT32 Function; 00320 00321 00322 ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField, ObjDesc); 00323 00324 00325 /* Parameter validation */ 00326 00327 if (!SourceDesc || !ObjDesc) 00328 { 00329 return_ACPI_STATUS (AE_AML_NO_OPERAND); 00330 } 00331 00332 if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD) 00333 { 00334 /* 00335 * If the BufferField arguments have not been previously evaluated, 00336 * evaluate them now and save the results. 00337 */ 00338 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)) 00339 { 00340 Status = AcpiDsGetBufferFieldArguments (ObjDesc); 00341 if (ACPI_FAILURE (Status)) 00342 { 00343 return_ACPI_STATUS (Status); 00344 } 00345 } 00346 } 00347 else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) && 00348 (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS || 00349 ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI)) 00350 { 00351 /* 00352 * This is an SMBus or IPMI write. We will bypass the entire field 00353 * mechanism and handoff the buffer directly to the handler. For 00354 * these address spaces, the buffer is bi-directional; on a write, 00355 * return data is returned in the same buffer. 00356 * 00357 * Source must be a buffer of sufficient size: 00358 * ACPI_SMBUS_BUFFER_SIZE or ACPI_IPMI_BUFFER_SIZE. 00359 * 00360 * Note: SMBus protocol type is passed in upper 16-bits of Function 00361 */ 00362 if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER) 00363 { 00364 ACPI_ERROR ((AE_INFO, 00365 "SMBus or IPMI write requires Buffer, found type %s", 00366 AcpiUtGetObjectTypeName (SourceDesc))); 00367 00368 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 00369 } 00370 00371 if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS) 00372 { 00373 Length = ACPI_SMBUS_BUFFER_SIZE; 00374 Function = ACPI_WRITE | (ObjDesc->Field.Attribute << 16); 00375 } 00376 else /* IPMI */ 00377 { 00378 Length = ACPI_IPMI_BUFFER_SIZE; 00379 Function = ACPI_WRITE; 00380 } 00381 00382 if (SourceDesc->Buffer.Length < Length) 00383 { 00384 ACPI_ERROR ((AE_INFO, 00385 "SMBus or IPMI write requires Buffer of length %u, found length %u", 00386 Length, SourceDesc->Buffer.Length)); 00387 00388 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT); 00389 } 00390 00391 /* Create the bi-directional buffer */ 00392 00393 BufferDesc = AcpiUtCreateBufferObject (Length); 00394 if (!BufferDesc) 00395 { 00396 return_ACPI_STATUS (AE_NO_MEMORY); 00397 } 00398 00399 Buffer = BufferDesc->Buffer.Pointer; 00400 ACPI_MEMCPY (Buffer, SourceDesc->Buffer.Pointer, Length); 00401 00402 /* Lock entire transaction if requested */ 00403 00404 AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags); 00405 00406 /* 00407 * Perform the write (returns status and perhaps data in the 00408 * same buffer) 00409 */ 00410 Status = AcpiExAccessRegion (ObjDesc, 0, 00411 (UINT64 *) Buffer, Function); 00412 AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags); 00413 00414 *ResultDesc = BufferDesc; 00415 return_ACPI_STATUS (Status); 00416 } 00417 00418 /* Get a pointer to the data to be written */ 00419 00420 switch (SourceDesc->Common.Type) 00421 { 00422 case ACPI_TYPE_INTEGER: 00423 Buffer = &SourceDesc->Integer.Value; 00424 Length = sizeof (SourceDesc->Integer.Value); 00425 break; 00426 00427 case ACPI_TYPE_BUFFER: 00428 Buffer = SourceDesc->Buffer.Pointer; 00429 Length = SourceDesc->Buffer.Length; 00430 break; 00431 00432 case ACPI_TYPE_STRING: 00433 Buffer = SourceDesc->String.Pointer; 00434 Length = SourceDesc->String.Length; 00435 break; 00436 00437 default: 00438 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 00439 } 00440 00441 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 00442 "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n", 00443 SourceDesc, AcpiUtGetTypeName (SourceDesc->Common.Type), 00444 SourceDesc->Common.Type, Buffer, Length)); 00445 00446 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 00447 "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n", 00448 ObjDesc, AcpiUtGetTypeName (ObjDesc->Common.Type), 00449 ObjDesc->Common.Type, 00450 ObjDesc->CommonField.BitLength, 00451 ObjDesc->CommonField.StartFieldBitOffset, 00452 ObjDesc->CommonField.BaseByteOffset)); 00453 00454 /* Lock entire transaction if requested */ 00455 00456 AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags); 00457 00458 /* Write to the field */ 00459 00460 Status = AcpiExInsertIntoField (ObjDesc, Buffer, Length); 00461 AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags); 00462 00463 return_ACPI_STATUS (Status); 00464 } 00465 00466 Generated on Sun May 27 2012 04:27:16 for ReactOS by
1.7.6.1
|