exfield.c revision 67754
1117756Sdeischen/****************************************************************************** 2117756Sdeischen * 3118510Sdeischen * Module Name: amfield - ACPI AML (p-code) execution - field manipulation 4 * $Revision: 73 $ 5 * 6 *****************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999, Intel Corp. All rights 13 * reserved. 14 * 15 * 2. License 16 * 17 * 2.1. This is your license from Intel Corp. under its intellectual property 18 * rights. You may have additional license terms from the party that provided 19 * you this software, covering your right to use that party's intellectual 20 * property rights. 21 * 22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23 * copy of the source code appearing in this file ("Covered Code") an 24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25 * base code distributed originally by Intel ("Original Intel Code") to copy, 26 * make derivatives, distribute, use and display any portion of the Covered 27 * Code in any form, with the right to sublicense such rights; and 28 * 29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30 * license (with the right to sublicense), under only those claims of Intel 31 * patents that are infringed by the Original Intel Code, to make, use, sell, 32 * offer to sell, and import the Covered Code and derivative works thereof 33 * solely to the minimum extent necessary to exercise the above copyright 34 * license, and in no event shall the patent license extend to any additions 35 * to or modifications of the Original Intel Code. No other license or right 36 * is granted directly or by implication, estoppel or otherwise; 37 * 38 * The above copyright and patent license is granted only if the following 39 * conditions are met: 40 * 41 * 3. Conditions 42 * 43 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44 * Redistribution of source code of any substantial portion of the Covered 45 * Code or modification with rights to further distribute source must include 46 * the above Copyright Notice, the above License, this list of Conditions, 47 * and the following Disclaimer and Export Compliance provision. In addition, 48 * Licensee must cause all Covered Code to which Licensee contributes to 49 * contain a file documenting the changes Licensee made to create that Covered 50 * Code and the date of any change. Licensee must include in that file the 51 * documentation of any changes made by any predecessor Licensee. Licensee 52 * must include a prominent statement that the modification is derived, 53 * directly or indirectly, from Original Intel Code. 54 * 55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56 * Redistribution of source code of any substantial portion of the Covered 57 * Code or modification without rights to further distribute source must 58 * include the following Disclaimer and Export Compliance provision in the 59 * documentation and/or other materials provided with distribution. In 60 * addition, Licensee may not authorize further sublicense of source of any 61 * portion of the Covered Code, and must include terms to the effect that the 62 * license from Licensee to its licensee is limited to the intellectual 63 * property embodied in the software Licensee provides to its licensee, and 64 * not to intellectual property embodied in modifications its licensee may 65 * make. 66 * 67 * 3.3. Redistribution of Executable. Redistribution in executable form of any 68 * substantial portion of the Covered Code or modification must reproduce the 69 * above Copyright Notice, and the following Disclaimer and Export Compliance 70 * provision in the documentation and/or other materials provided with the 71 * distribution. 72 * 73 * 3.4. Intel retains all right, title, and interest in and to the Original 74 * Intel Code. 75 * 76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77 * Intel shall be used in advertising or otherwise to promote the sale, use or 78 * other dealings in products derived from or relating to the Covered Code 79 * without prior written authorization from Intel. 80 * 81 * 4. Disclaimer and Export Compliance 82 * 83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89 * PARTICULAR PURPOSE. 90 * 91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98 * LIMITED REMEDY. 99 * 100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 101 * software or system incorporating such software without first obtaining any 102 * required license or other approval from the U. S. Department of Commerce or 103 * any other agency or department of the United States Government. In the 104 * event Licensee exports any such software from the United States or 105 * re-exports any such software from a foreign destination, Licensee shall 106 * ensure that the distribution and export/re-export of the software is in 107 * compliance with all laws, regulations, orders, or other restrictions of the 108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109 * any of its subsidiaries will export/re-export any technical data, process, 110 * software, or service, directly or indirectly, to any country for which the 111 * United States government or any agency thereof requires an export license, 112 * other governmental approval, or letter of assurance, without first obtaining 113 * such license, approval or letter. 114 * 115 *****************************************************************************/ 116 117 118#define __AMFIELD_C__ 119 120#include "acpi.h" 121#include "acdispat.h" 122#include "acinterp.h" 123#include "amlcode.h" 124#include "acnamesp.h" 125#include "achware.h" 126#include "acevents.h" 127 128 129#define _COMPONENT INTERPRETER 130 MODULE_NAME ("amfield") 131 132 133/******************************************************************************* 134 * 135 * FUNCTION: AcpiAmlSetupField 136 * 137 * PARAMETERS: *ObjDesc - Field to be read or written 138 * *RgnDesc - Region containing field 139 * FieldBitWidth - Field Width in bits (8, 16, or 32) 140 * 141 * RETURN: Status 142 * 143 * DESCRIPTION: Common processing for AcpiAmlReadField and AcpiAmlWriteField 144 * 145 * ACPI SPECIFICATION REFERENCES: 146 * Each of the Type1Opcodes is defined as specified in in-line 147 * comments below. For each one, use the following definitions. 148 * 149 * DefBitField := BitFieldOp SrcBuf BitIdx Destination 150 * DefByteField := ByteFieldOp SrcBuf ByteIdx Destination 151 * DefCreateField := CreateFieldOp SrcBuf BitIdx NumBits NameString 152 * DefDWordField := DWordFieldOp SrcBuf ByteIdx Destination 153 * DefWordField := WordFieldOp SrcBuf ByteIdx Destination 154 * BitIndex := TermArg=>Integer 155 * ByteIndex := TermArg=>Integer 156 * Destination := NameString 157 * NumBits := TermArg=>Integer 158 * SourceBuf := TermArg=>Buffer 159 * 160 ******************************************************************************/ 161 162ACPI_STATUS 163AcpiAmlSetupField ( 164 ACPI_OPERAND_OBJECT *ObjDesc, 165 ACPI_OPERAND_OBJECT *RgnDesc, 166 UINT32 FieldBitWidth) 167{ 168 ACPI_STATUS Status = AE_OK; 169 UINT32 FieldByteWidth; 170 171 172 FUNCTION_TRACE ("AmlSetupField"); 173 174 175 /* Parameter validation */ 176 177 if (!ObjDesc || !RgnDesc) 178 { 179 DEBUG_PRINT (ACPI_ERROR, 180 ("AmlSetupField: Internal error - null handle\n")); 181 return_ACPI_STATUS (AE_AML_NO_OPERAND); 182 } 183 184 if (ACPI_TYPE_REGION != RgnDesc->Common.Type) 185 { 186 DEBUG_PRINT (ACPI_ERROR, 187 ("AmlSetupField: Needed Region, found type %x %s\n", 188 RgnDesc->Common.Type, AcpiCmGetTypeName (RgnDesc->Common.Type))); 189 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 190 } 191 192 193 /* 194 * TBD: [Future] Acpi 2.0 supports Qword fields 195 * 196 * Init and validate Field width 197 * Possible values are 1, 2, 4 198 */ 199 200 FieldByteWidth = DIV_8 (FieldBitWidth); 201 202 if ((FieldBitWidth != 8) && 203 (FieldBitWidth != 16) && 204 (FieldBitWidth != 32)) 205 { 206 DEBUG_PRINT (ACPI_ERROR, 207 ("AmlSetupField: Internal error - bad width %d\n", FieldBitWidth)); 208 return_ACPI_STATUS (AE_AML_OPERAND_VALUE); 209 } 210 211 212 /* 213 * If the Region Address and Length have not been previously evaluated, 214 * evaluate them and save the results. 215 */ 216 if (!(RgnDesc->Region.Flags & AOPOBJ_DATA_VALID)) 217 { 218 219 Status = AcpiDsGetRegionArguments (RgnDesc); 220 if (ACPI_FAILURE (Status)) 221 { 222 return_ACPI_STATUS (Status); 223 } 224 } 225 226 227 if ((ObjDesc->Common.Type == ACPI_TYPE_FIELD_UNIT) && 228 (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))) 229 { 230 /* 231 * Field Buffer and Index have not been previously evaluated, 232 */ 233 DEBUG_PRINT (ACPI_ERROR, ("Uninitialized field!\n")); 234 return_ACPI_STATUS (AE_AML_INTERNAL); 235 } 236 237 if (RgnDesc->Region.Length < 238 (ObjDesc->Field.Offset & ~((UINT32) FieldByteWidth - 1)) + 239 FieldByteWidth) 240 { 241 /* 242 * Offset rounded up to next multiple of field width 243 * exceeds region length, indicate an error 244 */ 245 246 DUMP_STACK_ENTRY (RgnDesc); 247 DUMP_STACK_ENTRY (ObjDesc); 248 249 DEBUG_PRINT (ACPI_ERROR, 250 ("AmlSetupField: Operation at %08lX width %d bits exceeds len %08lX field=%p region=%p\n", 251 ObjDesc->Field.Offset, FieldBitWidth, RgnDesc->Region.Length, 252 ObjDesc, RgnDesc)); 253 254 return_ACPI_STATUS (AE_AML_REGION_LIMIT); 255 } 256 257 return_ACPI_STATUS (AE_OK); 258} 259 260 261/******************************************************************************* 262 * 263 * FUNCTION: AcpiAmlAccessNamedField 264 * 265 * PARAMETERS: Mode - ACPI_READ or ACPI_WRITE 266 * NamedField - Handle for field to be accessed 267 * *Buffer - Value(s) to be read or written 268 * BufferLength - Number of bytes to transfer 269 * 270 * RETURN: Status 271 * 272 * DESCRIPTION: Read or write a named field 273 * 274 ******************************************************************************/ 275 276ACPI_STATUS 277AcpiAmlAccessNamedField ( 278 UINT32 Mode, 279 ACPI_HANDLE NamedField, 280 void *Buffer, 281 UINT32 BufferLength) 282{ 283 ACPI_OPERAND_OBJECT *ObjDesc = NULL; 284 ACPI_STATUS Status = AE_OK; 285 BOOLEAN Locked = FALSE; 286 UINT32 BitGranularity = 0; 287 UINT32 ByteGranularity; 288 UINT32 DatumLength; 289 UINT32 ActualByteLength; 290 UINT32 ByteFieldLength; 291 292 293 FUNCTION_TRACE_PTR ("AmlAccessNamedField", NamedField); 294 295 296 /* Basic data checking */ 297 if ((!NamedField) || (ACPI_READ == Mode && !Buffer)) 298 { 299 DEBUG_PRINT (ACPI_ERROR, 300 ("AcpiAmlAccessNamedField: Internal error - null parameter\n")); 301 return_ACPI_STATUS (AE_AML_INTERNAL); 302 } 303 304 /* Get the attached field object */ 305 306 ObjDesc = AcpiNsGetAttachedObject (NamedField); 307 if (!ObjDesc) 308 { 309 DEBUG_PRINT (ACPI_ERROR, 310 ("AmlAccessNamedField: Internal error - null value pointer\n")); 311 return_ACPI_STATUS (AE_AML_INTERNAL); 312 } 313 314 /* Check the type */ 315 316 if (INTERNAL_TYPE_DEF_FIELD != AcpiNsGetType (NamedField)) 317 { 318 DEBUG_PRINT (ACPI_ERROR, 319 ("AmlAccessNamedField: Name %4.4s type %x is not a defined field\n", 320 &(((ACPI_NAMESPACE_NODE *) NamedField)->Name), 321 AcpiNsGetType (NamedField))); 322 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 323 } 324 325 /* ObjDesc valid and NamedField is a defined field */ 326 327 DEBUG_PRINT (ACPI_INFO, 328 ("AccessNamedField: Obj=%p Type=%x Buf=%p Len=%x\n", 329 ObjDesc, ObjDesc->Common.Type, Buffer, BufferLength)); 330 DEBUG_PRINT (ACPI_INFO, 331 ("AccessNamedField: Mode=%d FieldLen=%d, BitOffset=%d\n", 332 Mode, ObjDesc->FieldUnit.Length, ObjDesc->FieldUnit.BitOffset)); 333 DUMP_ENTRY (NamedField, ACPI_INFO); 334 335 336 /* Double-check that the attached object is also a field */ 337 338 if (INTERNAL_TYPE_DEF_FIELD != ObjDesc->Common.Type) 339 { 340 DEBUG_PRINT (ACPI_ERROR, 341 ("AmlAccessNamedField: Internal error - Name %4.4s type %x does not match value-type %x at %p\n", 342 &(((ACPI_NAMESPACE_NODE *) NamedField)->Name), 343 AcpiNsGetType (NamedField), ObjDesc->Common.Type, ObjDesc)); 344 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 345 } 346 347 348 /* 349 * Granularity was decoded from the field access type 350 * (AnyAcc will be the same as ByteAcc) 351 */ 352 353 BitGranularity = ObjDesc->FieldUnit.Granularity; 354 ByteGranularity = DIV_8 (BitGranularity); 355 356 /* 357 * Check if request is too large for the field, and silently truncate 358 * if necessary 359 */ 360 361 /* TBD: [Errors] should an error be returned in this case? */ 362 363 ByteFieldLength = (UINT32) DIV_8 (ObjDesc->FieldUnit.Length + 7); 364 365 366 ActualByteLength = BufferLength; 367 if (BufferLength > ByteFieldLength) 368 { 369 DEBUG_PRINT (ACPI_INFO, 370 ("AmlAccessNamedField: Byte length %d too large, truncated to %x\n", 371 ActualByteLength, ByteFieldLength)); 372 373 ActualByteLength = ByteFieldLength; 374 } 375 376 /* TBD: should these round down to a power of 2? */ 377 378 if (DIV_8(BitGranularity) > ByteFieldLength) 379 { 380 DEBUG_PRINT (ACPI_INFO, 381 ("AmlAccessNamedField: Bit granularity %d too large, truncated to %x\n", 382 BitGranularity, MUL_8(ByteFieldLength))); 383 384 BitGranularity = MUL_8(ByteFieldLength); 385 } 386 387 if (ByteGranularity > ByteFieldLength) 388 { 389 DEBUG_PRINT (ACPI_INFO, 390 ("AmlAccessNamedField: Byte granularity %d too large, truncated to %x\n", 391 ByteGranularity, ByteFieldLength)); 392 393 ByteGranularity = ByteFieldLength; 394 } 395 396 397 /* Convert byte count to datum count, round up if necessary */ 398 399 DatumLength = (ActualByteLength + (ByteGranularity-1)) / ByteGranularity; 400 401 DEBUG_PRINT (ACPI_INFO, 402 ("ByteLen=%x, DatumLen=%x, BitGran=%x, ByteGran=%x\n", 403 ActualByteLength, DatumLength, BitGranularity, ByteGranularity)); 404 405 406 /* Get the global lock if needed */ 407 408 Locked = AcpiAmlAcquireGlobalLock (ObjDesc->FieldUnit.LockRule); 409 410 411 /* Perform the actual read or write of the buffer */ 412 413 switch (Mode) 414 { 415 case ACPI_READ: 416 417 Status = AcpiAmlReadField (ObjDesc, Buffer, BufferLength, 418 ActualByteLength, DatumLength, 419 BitGranularity, ByteGranularity); 420 break; 421 422 423 case ACPI_WRITE: 424 425 Status = AcpiAmlWriteField (ObjDesc, Buffer, BufferLength, 426 ActualByteLength, DatumLength, 427 BitGranularity, ByteGranularity); 428 break; 429 430 431 default: 432 433 DEBUG_PRINT (ACPI_ERROR, 434 ("AccessNamedField: Unknown I/O Mode: %X\n", Mode)); 435 Status = AE_BAD_PARAMETER; 436 break; 437 } 438 439 440 /* Release global lock if we acquired it earlier */ 441 442 AcpiAmlReleaseGlobalLock (Locked); 443 444 return_ACPI_STATUS (Status); 445} 446 447