![]() |
|
|||
File indexing completed on 2025-05-11 08:24:02
0001 /****************************************************************************** 0002 * 0003 * Module Name: exprep - ACPI AML field prep utilities 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 "acinterp.h" 0155 #include "amlcode.h" 0156 #include "acnamesp.h" 0157 #include "acdispat.h" 0158 0159 0160 #define _COMPONENT ACPI_EXECUTER 0161 ACPI_MODULE_NAME ("exprep") 0162 0163 /* Local prototypes */ 0164 0165 static UINT32 0166 AcpiExDecodeFieldAccess ( 0167 ACPI_OPERAND_OBJECT *ObjDesc, 0168 UINT8 FieldFlags, 0169 UINT32 *ReturnByteAlignment); 0170 0171 0172 #ifdef ACPI_UNDER_DEVELOPMENT 0173 0174 static UINT32 0175 AcpiExGenerateAccess ( 0176 UINT32 FieldBitOffset, 0177 UINT32 FieldBitLength, 0178 UINT32 RegionLength); 0179 0180 0181 /******************************************************************************* 0182 * 0183 * FUNCTION: AcpiExGenerateAccess 0184 * 0185 * PARAMETERS: FieldBitOffset - Start of field within parent region/buffer 0186 * FieldBitLength - Length of field in bits 0187 * RegionLength - Length of parent in bytes 0188 * 0189 * RETURN: Field granularity (8, 16, 32 or 64) and 0190 * ByteAlignment (1, 2, 3, or 4) 0191 * 0192 * DESCRIPTION: Generate an optimal access width for fields defined with the 0193 * AnyAcc keyword. 0194 * 0195 * NOTE: Need to have the RegionLength in order to check for boundary 0196 * conditions (end-of-region). However, the RegionLength is a deferred 0197 * operation. Therefore, to complete this implementation, the generation 0198 * of this access width must be deferred until the region length has 0199 * been evaluated. 0200 * 0201 ******************************************************************************/ 0202 0203 static UINT32 0204 AcpiExGenerateAccess ( 0205 UINT32 FieldBitOffset, 0206 UINT32 FieldBitLength, 0207 UINT32 RegionLength) 0208 { 0209 UINT32 FieldByteLength; 0210 UINT32 FieldByteOffset; 0211 UINT32 FieldByteEndOffset; 0212 UINT32 AccessByteWidth; 0213 UINT32 FieldStartOffset; 0214 UINT32 FieldEndOffset; 0215 UINT32 MinimumAccessWidth = 0xFFFFFFFF; 0216 UINT32 MinimumAccesses = 0xFFFFFFFF; 0217 UINT32 Accesses; 0218 0219 0220 ACPI_FUNCTION_TRACE (ExGenerateAccess); 0221 0222 0223 /* Round Field start offset and length to "minimal" byte boundaries */ 0224 0225 FieldByteOffset = ACPI_DIV_8 ( 0226 ACPI_ROUND_DOWN (FieldBitOffset, 8)); 0227 0228 FieldByteEndOffset = ACPI_DIV_8 ( 0229 ACPI_ROUND_UP (FieldBitLength + FieldBitOffset, 8)); 0230 0231 FieldByteLength = FieldByteEndOffset - FieldByteOffset; 0232 0233 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0234 "Bit length %u, Bit offset %u\n", 0235 FieldBitLength, FieldBitOffset)); 0236 0237 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0238 "Byte Length %u, Byte Offset %u, End Offset %u\n", 0239 FieldByteLength, FieldByteOffset, FieldByteEndOffset)); 0240 0241 /* 0242 * Iterative search for the maximum access width that is both aligned 0243 * and does not go beyond the end of the region 0244 * 0245 * Start at ByteAcc and work upwards to QwordAcc max. (1,2,4,8 bytes) 0246 */ 0247 for (AccessByteWidth = 1; AccessByteWidth <= 8; AccessByteWidth <<= 1) 0248 { 0249 /* 0250 * 1) Round end offset up to next access boundary and make sure that 0251 * this does not go beyond the end of the parent region. 0252 * 2) When the Access width is greater than the FieldByteLength, we 0253 * are done. (This does not optimize for the perfectly aligned 0254 * case yet). 0255 */ 0256 if (ACPI_ROUND_UP (FieldByteEndOffset, AccessByteWidth) <= 0257 RegionLength) 0258 { 0259 FieldStartOffset = 0260 ACPI_ROUND_DOWN (FieldByteOffset, AccessByteWidth) / 0261 AccessByteWidth; 0262 0263 FieldEndOffset = 0264 ACPI_ROUND_UP ((FieldByteLength + FieldByteOffset), 0265 AccessByteWidth) / AccessByteWidth; 0266 0267 Accesses = FieldEndOffset - FieldStartOffset; 0268 0269 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0270 "AccessWidth %u end is within region\n", AccessByteWidth)); 0271 0272 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0273 "Field Start %u, Field End %u -- requires %u accesses\n", 0274 FieldStartOffset, FieldEndOffset, Accesses)); 0275 0276 /* Single access is optimal */ 0277 0278 if (Accesses <= 1) 0279 { 0280 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0281 "Entire field can be accessed " 0282 "with one operation of size %u\n", 0283 AccessByteWidth)); 0284 return_VALUE (AccessByteWidth); 0285 } 0286 0287 /* 0288 * Fits in the region, but requires more than one read/write. 0289 * try the next wider access on next iteration 0290 */ 0291 if (Accesses < MinimumAccesses) 0292 { 0293 MinimumAccesses = Accesses; 0294 MinimumAccessWidth = AccessByteWidth; 0295 } 0296 } 0297 else 0298 { 0299 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0300 "AccessWidth %u end is NOT within region\n", 0301 AccessByteWidth)); 0302 if (AccessByteWidth == 1) 0303 { 0304 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0305 "Field goes beyond end-of-region!\n")); 0306 0307 /* Field does not fit in the region at all */ 0308 0309 return_VALUE (0); 0310 } 0311 0312 /* 0313 * This width goes beyond the end-of-region, back off to 0314 * previous access 0315 */ 0316 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0317 "Backing off to previous optimal access width of %u\n", 0318 MinimumAccessWidth)); 0319 return_VALUE (MinimumAccessWidth); 0320 } 0321 } 0322 0323 /* 0324 * Could not read/write field with one operation, 0325 * just use max access width 0326 */ 0327 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0328 "Cannot access field in one operation, using width 8\n")); 0329 0330 return_VALUE (8); 0331 } 0332 #endif /* ACPI_UNDER_DEVELOPMENT */ 0333 0334 0335 /******************************************************************************* 0336 * 0337 * FUNCTION: AcpiExDecodeFieldAccess 0338 * 0339 * PARAMETERS: ObjDesc - Field object 0340 * FieldFlags - Encoded fieldflags (contains access bits) 0341 * ReturnByteAlignment - Where the byte alignment is returned 0342 * 0343 * RETURN: Field granularity (8, 16, 32 or 64) and 0344 * ByteAlignment (1, 2, 3, or 4) 0345 * 0346 * DESCRIPTION: Decode the AccessType bits of a field definition. 0347 * 0348 ******************************************************************************/ 0349 0350 static UINT32 0351 AcpiExDecodeFieldAccess ( 0352 ACPI_OPERAND_OBJECT *ObjDesc, 0353 UINT8 FieldFlags, 0354 UINT32 *ReturnByteAlignment) 0355 { 0356 UINT32 Access; 0357 UINT32 ByteAlignment; 0358 UINT32 BitLength; 0359 0360 0361 ACPI_FUNCTION_TRACE (ExDecodeFieldAccess); 0362 0363 0364 Access = (FieldFlags & AML_FIELD_ACCESS_TYPE_MASK); 0365 0366 switch (Access) 0367 { 0368 case AML_FIELD_ACCESS_ANY: 0369 0370 #ifdef ACPI_UNDER_DEVELOPMENT 0371 ByteAlignment = 0372 AcpiExGenerateAccess (ObjDesc->CommonField.StartFieldBitOffset, 0373 ObjDesc->CommonField.BitLength, 0374 0xFFFFFFFF /* Temp until we pass RegionLength as parameter */); 0375 BitLength = ByteAlignment * 8; 0376 #endif 0377 0378 ByteAlignment = 1; 0379 BitLength = 8; 0380 break; 0381 0382 case AML_FIELD_ACCESS_BYTE: 0383 case AML_FIELD_ACCESS_BUFFER: /* ACPI 2.0 (SMBus Buffer) */ 0384 0385 ByteAlignment = 1; 0386 BitLength = 8; 0387 break; 0388 0389 case AML_FIELD_ACCESS_WORD: 0390 0391 ByteAlignment = 2; 0392 BitLength = 16; 0393 break; 0394 0395 case AML_FIELD_ACCESS_DWORD: 0396 0397 ByteAlignment = 4; 0398 BitLength = 32; 0399 break; 0400 0401 case AML_FIELD_ACCESS_QWORD: /* ACPI 2.0 */ 0402 0403 ByteAlignment = 8; 0404 BitLength = 64; 0405 break; 0406 0407 default: 0408 0409 /* Invalid field access type */ 0410 0411 ACPI_ERROR ((AE_INFO, 0412 "Unknown field access type 0x%X", 0413 Access)); 0414 0415 return_UINT32 (0); 0416 } 0417 0418 if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD) 0419 { 0420 /* 0421 * BufferField access can be on any byte boundary, so the 0422 * ByteAlignment is always 1 byte -- regardless of any ByteAlignment 0423 * implied by the field access type. 0424 */ 0425 ByteAlignment = 1; 0426 } 0427 0428 *ReturnByteAlignment = ByteAlignment; 0429 return_UINT32 (BitLength); 0430 } 0431 0432 0433 /******************************************************************************* 0434 * 0435 * FUNCTION: AcpiExPrepCommonFieldObject 0436 * 0437 * PARAMETERS: ObjDesc - The field object 0438 * FieldFlags - Access, LockRule, and UpdateRule. 0439 * The format of a FieldFlag is described 0440 * in the ACPI specification 0441 * FieldAttribute - Special attributes (not used) 0442 * FieldBitPosition - Field start position 0443 * FieldBitLength - Field length in number of bits 0444 * 0445 * RETURN: Status 0446 * 0447 * DESCRIPTION: Initialize the areas of the field object that are common 0448 * to the various types of fields. Note: This is very "sensitive" 0449 * code because we are solving the general case for field 0450 * alignment. 0451 * 0452 ******************************************************************************/ 0453 0454 ACPI_STATUS 0455 AcpiExPrepCommonFieldObject ( 0456 ACPI_OPERAND_OBJECT *ObjDesc, 0457 UINT8 FieldFlags, 0458 UINT8 FieldAttribute, 0459 UINT32 FieldBitPosition, 0460 UINT32 FieldBitLength) 0461 { 0462 UINT32 AccessBitWidth; 0463 UINT32 ByteAlignment; 0464 UINT32 NearestByteAddress; 0465 0466 0467 ACPI_FUNCTION_TRACE (ExPrepCommonFieldObject); 0468 0469 0470 /* 0471 * Note: the structure being initialized is the 0472 * ACPI_COMMON_FIELD_INFO; No structure fields outside of the common 0473 * area are initialized by this procedure. 0474 */ 0475 ObjDesc->CommonField.FieldFlags = FieldFlags; 0476 ObjDesc->CommonField.Attribute = FieldAttribute; 0477 ObjDesc->CommonField.BitLength = FieldBitLength; 0478 0479 /* 0480 * Decode the access type so we can compute offsets. The access type gives 0481 * two pieces of information - the width of each field access and the 0482 * necessary ByteAlignment (address granularity) of the access. 0483 * 0484 * For AnyAcc, the AccessBitWidth is the largest width that is both 0485 * necessary and possible in an attempt to access the whole field in one 0486 * I/O operation. However, for AnyAcc, the ByteAlignment is always one 0487 * byte. 0488 * 0489 * For all Buffer Fields, the ByteAlignment is always one byte. 0490 * 0491 * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is 0492 * the same (equivalent) as the ByteAlignment. 0493 */ 0494 AccessBitWidth = AcpiExDecodeFieldAccess ( 0495 ObjDesc, FieldFlags, &ByteAlignment); 0496 if (!AccessBitWidth) 0497 { 0498 return_ACPI_STATUS (AE_AML_OPERAND_VALUE); 0499 } 0500 0501 /* Setup width (access granularity) fields (values are: 1, 2, 4, 8) */ 0502 0503 ObjDesc->CommonField.AccessByteWidth = (UINT8) 0504 ACPI_DIV_8 (AccessBitWidth); 0505 0506 /* 0507 * BaseByteOffset is the address of the start of the field within the 0508 * region. It is the byte address of the first *datum* (field-width data 0509 * unit) of the field. (i.e., the first datum that contains at least the 0510 * first *bit* of the field.) 0511 * 0512 * Note: ByteAlignment is always either equal to the AccessBitWidth or 8 0513 * (Byte access), and it defines the addressing granularity of the parent 0514 * region or buffer. 0515 */ 0516 NearestByteAddress = 0517 ACPI_ROUND_BITS_DOWN_TO_BYTES (FieldBitPosition); 0518 ObjDesc->CommonField.BaseByteOffset = (UINT32) 0519 ACPI_ROUND_DOWN (NearestByteAddress, ByteAlignment); 0520 0521 /* 0522 * StartFieldBitOffset is the offset of the first bit of the field within 0523 * a field datum. 0524 */ 0525 ObjDesc->CommonField.StartFieldBitOffset = (UINT8) 0526 (FieldBitPosition - ACPI_MUL_8 (ObjDesc->CommonField.BaseByteOffset)); 0527 0528 return_ACPI_STATUS (AE_OK); 0529 } 0530 0531 0532 /******************************************************************************* 0533 * 0534 * FUNCTION: AcpiExPrepFieldValue 0535 * 0536 * PARAMETERS: Info - Contains all field creation info 0537 * 0538 * RETURN: Status 0539 * 0540 * DESCRIPTION: Construct an object of type ACPI_OPERAND_OBJECT with a 0541 * subtype of DefField and connect it to the parent Node. 0542 * 0543 ******************************************************************************/ 0544 0545 ACPI_STATUS 0546 AcpiExPrepFieldValue ( 0547 ACPI_CREATE_FIELD_INFO *Info) 0548 { 0549 ACPI_OPERAND_OBJECT *ObjDesc; 0550 ACPI_OPERAND_OBJECT *SecondDesc = NULL; 0551 ACPI_STATUS Status; 0552 UINT32 AccessByteWidth; 0553 UINT32 Type; 0554 0555 0556 ACPI_FUNCTION_TRACE (ExPrepFieldValue); 0557 0558 0559 /* Parameter validation */ 0560 0561 if (Info->FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD) 0562 { 0563 if (!Info->RegionNode) 0564 { 0565 ACPI_ERROR ((AE_INFO, "Null RegionNode")); 0566 return_ACPI_STATUS (AE_AML_NO_OPERAND); 0567 } 0568 0569 Type = AcpiNsGetType (Info->RegionNode); 0570 if (Type != ACPI_TYPE_REGION) 0571 { 0572 ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)", 0573 Type, AcpiUtGetTypeName (Type))); 0574 0575 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 0576 } 0577 } 0578 0579 /* Allocate a new field object */ 0580 0581 ObjDesc = AcpiUtCreateInternalObject (Info->FieldType); 0582 if (!ObjDesc) 0583 { 0584 return_ACPI_STATUS (AE_NO_MEMORY); 0585 } 0586 0587 /* Initialize areas of the object that are common to all fields */ 0588 0589 ObjDesc->CommonField.Node = Info->FieldNode; 0590 Status = AcpiExPrepCommonFieldObject (ObjDesc, 0591 Info->FieldFlags, Info->Attribute, 0592 Info->FieldBitPosition, Info->FieldBitLength); 0593 if (ACPI_FAILURE (Status)) 0594 { 0595 AcpiUtDeleteObjectDesc (ObjDesc); 0596 return_ACPI_STATUS (Status); 0597 } 0598 0599 /* Initialize areas of the object that are specific to the field type */ 0600 0601 switch (Info->FieldType) 0602 { 0603 case ACPI_TYPE_LOCAL_REGION_FIELD: 0604 0605 ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (Info->RegionNode); 0606 0607 /* Fields specific to GenericSerialBus fields */ 0608 0609 ObjDesc->Field.AccessLength = Info->AccessLength; 0610 0611 if (Info->ConnectionNode) 0612 { 0613 SecondDesc = Info->ConnectionNode->Object; 0614 if (!(SecondDesc->Common.Flags & AOPOBJ_DATA_VALID)) 0615 { 0616 Status = AcpiDsGetBufferArguments (SecondDesc); 0617 if (ACPI_FAILURE (Status)) 0618 { 0619 AcpiUtDeleteObjectDesc (ObjDesc); 0620 return_ACPI_STATUS (Status); 0621 } 0622 } 0623 0624 ObjDesc->Field.ResourceBuffer = 0625 SecondDesc->Buffer.Pointer; 0626 ObjDesc->Field.ResourceLength = 0627 (UINT16) SecondDesc->Buffer.Length; 0628 } 0629 else if (Info->ResourceBuffer) 0630 { 0631 ObjDesc->Field.ResourceBuffer = Info->ResourceBuffer; 0632 ObjDesc->Field.ResourceLength = Info->ResourceLength; 0633 } 0634 0635 ObjDesc->Field.PinNumberIndex = Info->PinNumberIndex; 0636 0637 /* Allow full data read from EC address space */ 0638 0639 if ((ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) && 0640 (ObjDesc->CommonField.BitLength > 8)) 0641 { 0642 AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES ( 0643 ObjDesc->CommonField.BitLength); 0644 0645 /* Maximum byte width supported is 255 */ 0646 0647 if (AccessByteWidth < 256) 0648 { 0649 ObjDesc->CommonField.AccessByteWidth = 0650 (UINT8) AccessByteWidth; 0651 } 0652 } 0653 0654 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0655 "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n", 0656 ObjDesc->Field.StartFieldBitOffset, 0657 ObjDesc->Field.BaseByteOffset, 0658 ObjDesc->Field.AccessByteWidth, 0659 ObjDesc->Field.RegionObj)); 0660 break; 0661 0662 case ACPI_TYPE_LOCAL_BANK_FIELD: 0663 0664 ObjDesc->BankField.Value = Info->BankValue; 0665 ObjDesc->BankField.RegionObj = 0666 AcpiNsGetAttachedObject (Info->RegionNode); 0667 ObjDesc->BankField.BankObj = 0668 AcpiNsGetAttachedObject (Info->RegisterNode); 0669 0670 /* An additional reference for the attached objects */ 0671 0672 AcpiUtAddReference (ObjDesc->BankField.RegionObj); 0673 AcpiUtAddReference (ObjDesc->BankField.BankObj); 0674 0675 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0676 "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n", 0677 ObjDesc->BankField.StartFieldBitOffset, 0678 ObjDesc->BankField.BaseByteOffset, 0679 ObjDesc->Field.AccessByteWidth, 0680 ObjDesc->BankField.RegionObj, 0681 ObjDesc->BankField.BankObj)); 0682 0683 /* 0684 * Remember location in AML stream of the field unit 0685 * opcode and operands -- since the BankValue 0686 * operands must be evaluated. 0687 */ 0688 SecondDesc = ObjDesc->Common.NextObject; 0689 SecondDesc->Extra.AmlStart = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, 0690 Info->DataRegisterNode)->Named.Data; 0691 SecondDesc->Extra.AmlLength = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, 0692 Info->DataRegisterNode)->Named.Length; 0693 0694 break; 0695 0696 case ACPI_TYPE_LOCAL_INDEX_FIELD: 0697 0698 /* Get the Index and Data registers */ 0699 0700 ObjDesc->IndexField.IndexObj = 0701 AcpiNsGetAttachedObject (Info->RegisterNode); 0702 ObjDesc->IndexField.DataObj = 0703 AcpiNsGetAttachedObject (Info->DataRegisterNode); 0704 0705 if (!ObjDesc->IndexField.DataObj || !ObjDesc->IndexField.IndexObj) 0706 { 0707 ACPI_ERROR ((AE_INFO, "Null Index Object during field prep")); 0708 AcpiUtDeleteObjectDesc (ObjDesc); 0709 return_ACPI_STATUS (AE_AML_INTERNAL); 0710 } 0711 0712 /* An additional reference for the attached objects */ 0713 0714 AcpiUtAddReference (ObjDesc->IndexField.DataObj); 0715 AcpiUtAddReference (ObjDesc->IndexField.IndexObj); 0716 0717 /* 0718 * April 2006: Changed to match MS behavior 0719 * 0720 * The value written to the Index register is the byte offset of the 0721 * target field in units of the granularity of the IndexField 0722 * 0723 * Previously, the value was calculated as an index in terms of the 0724 * width of the Data register, as below: 0725 * 0726 * ObjDesc->IndexField.Value = (UINT32) 0727 * (Info->FieldBitPosition / ACPI_MUL_8 ( 0728 * ObjDesc->Field.AccessByteWidth)); 0729 * 0730 * February 2006: Tried value as a byte offset: 0731 * ObjDesc->IndexField.Value = (UINT32) 0732 * ACPI_DIV_8 (Info->FieldBitPosition); 0733 */ 0734 ObjDesc->IndexField.Value = (UINT32) ACPI_ROUND_DOWN ( 0735 ACPI_DIV_8 (Info->FieldBitPosition), 0736 ObjDesc->IndexField.AccessByteWidth); 0737 0738 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0739 "IndexField: BitOff %X, Off %X, Value %X, " 0740 "Gran %X, Index %p, Data %p\n", 0741 ObjDesc->IndexField.StartFieldBitOffset, 0742 ObjDesc->IndexField.BaseByteOffset, 0743 ObjDesc->IndexField.Value, 0744 ObjDesc->Field.AccessByteWidth, 0745 ObjDesc->IndexField.IndexObj, 0746 ObjDesc->IndexField.DataObj)); 0747 break; 0748 0749 default: 0750 0751 /* No other types should get here */ 0752 0753 break; 0754 } 0755 0756 /* 0757 * Store the constructed descriptor (ObjDesc) into the parent Node, 0758 * preserving the current type of that NamedObj. 0759 */ 0760 Status = AcpiNsAttachObject ( 0761 Info->FieldNode, ObjDesc, AcpiNsGetType (Info->FieldNode)); 0762 0763 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 0764 "Set NamedObj %p [%4.4s], ObjDesc %p\n", 0765 Info->FieldNode, AcpiUtGetNodeName (Info->FieldNode), ObjDesc)); 0766 0767 /* Remove local reference to the object */ 0768 0769 AcpiUtRemoveReference (ObjDesc); 0770 return_ACPI_STATUS (Status); 0771 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |