1 1.1 jruoho /****************************************************************************** 2 1.1 jruoho * 3 1.1.1.6 christos * Module Name: exprep - ACPI AML field prep utilities 4 1.1 jruoho * 5 1.1 jruoho *****************************************************************************/ 6 1.1 jruoho 7 1.1.1.16 christos /****************************************************************************** 8 1.1.1.16 christos * 9 1.1.1.16 christos * 1. Copyright Notice 10 1.1.1.16 christos * 11 1.1.1.17 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp. 12 1.1 jruoho * All rights reserved. 13 1.1 jruoho * 14 1.1.1.16 christos * 2. License 15 1.1.1.16 christos * 16 1.1.1.16 christos * 2.1. This is your license from Intel Corp. under its intellectual property 17 1.1.1.16 christos * rights. You may have additional license terms from the party that provided 18 1.1.1.16 christos * you this software, covering your right to use that party's intellectual 19 1.1.1.16 christos * property rights. 20 1.1.1.16 christos * 21 1.1.1.16 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 1.1.1.16 christos * copy of the source code appearing in this file ("Covered Code") an 23 1.1.1.16 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 1.1.1.16 christos * base code distributed originally by Intel ("Original Intel Code") to copy, 25 1.1.1.16 christos * make derivatives, distribute, use and display any portion of the Covered 26 1.1.1.16 christos * Code in any form, with the right to sublicense such rights; and 27 1.1.1.16 christos * 28 1.1.1.16 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 1.1.1.16 christos * license (with the right to sublicense), under only those claims of Intel 30 1.1.1.16 christos * patents that are infringed by the Original Intel Code, to make, use, sell, 31 1.1.1.16 christos * offer to sell, and import the Covered Code and derivative works thereof 32 1.1.1.16 christos * solely to the minimum extent necessary to exercise the above copyright 33 1.1.1.16 christos * license, and in no event shall the patent license extend to any additions 34 1.1.1.16 christos * to or modifications of the Original Intel Code. No other license or right 35 1.1.1.16 christos * is granted directly or by implication, estoppel or otherwise; 36 1.1.1.16 christos * 37 1.1.1.16 christos * The above copyright and patent license is granted only if the following 38 1.1.1.16 christos * conditions are met: 39 1.1.1.16 christos * 40 1.1.1.16 christos * 3. Conditions 41 1.1.1.16 christos * 42 1.1.1.16 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 1.1.1.16 christos * Redistribution of source code of any substantial portion of the Covered 44 1.1.1.16 christos * Code or modification with rights to further distribute source must include 45 1.1.1.16 christos * the above Copyright Notice, the above License, this list of Conditions, 46 1.1.1.16 christos * and the following Disclaimer and Export Compliance provision. In addition, 47 1.1.1.16 christos * Licensee must cause all Covered Code to which Licensee contributes to 48 1.1.1.16 christos * contain a file documenting the changes Licensee made to create that Covered 49 1.1.1.16 christos * Code and the date of any change. Licensee must include in that file the 50 1.1.1.16 christos * documentation of any changes made by any predecessor Licensee. Licensee 51 1.1.1.16 christos * must include a prominent statement that the modification is derived, 52 1.1.1.16 christos * directly or indirectly, from Original Intel Code. 53 1.1.1.16 christos * 54 1.1.1.16 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 1.1.1.16 christos * Redistribution of source code of any substantial portion of the Covered 56 1.1.1.16 christos * Code or modification without rights to further distribute source must 57 1.1.1.16 christos * include the following Disclaimer and Export Compliance provision in the 58 1.1.1.16 christos * documentation and/or other materials provided with distribution. In 59 1.1.1.16 christos * addition, Licensee may not authorize further sublicense of source of any 60 1.1.1.16 christos * portion of the Covered Code, and must include terms to the effect that the 61 1.1.1.16 christos * license from Licensee to its licensee is limited to the intellectual 62 1.1.1.16 christos * property embodied in the software Licensee provides to its licensee, and 63 1.1.1.16 christos * not to intellectual property embodied in modifications its licensee may 64 1.1.1.16 christos * make. 65 1.1.1.16 christos * 66 1.1.1.16 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 1.1.1.16 christos * substantial portion of the Covered Code or modification must reproduce the 68 1.1.1.16 christos * above Copyright Notice, and the following Disclaimer and Export Compliance 69 1.1.1.16 christos * provision in the documentation and/or other materials provided with the 70 1.1.1.16 christos * distribution. 71 1.1.1.16 christos * 72 1.1.1.16 christos * 3.4. Intel retains all right, title, and interest in and to the Original 73 1.1.1.16 christos * Intel Code. 74 1.1.1.16 christos * 75 1.1.1.16 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 1.1.1.16 christos * Intel shall be used in advertising or otherwise to promote the sale, use or 77 1.1.1.16 christos * other dealings in products derived from or relating to the Covered Code 78 1.1.1.16 christos * without prior written authorization from Intel. 79 1.1.1.16 christos * 80 1.1.1.16 christos * 4. Disclaimer and Export Compliance 81 1.1.1.16 christos * 82 1.1.1.16 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 1.1.1.16 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 1.1.1.16 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 1.1.1.16 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 1.1.1.16 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 1.1.1.16 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 1.1.1.16 christos * PARTICULAR PURPOSE. 89 1.1.1.16 christos * 90 1.1.1.16 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 1.1.1.16 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 1.1.1.16 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 1.1.1.16 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 1.1.1.16 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 1.1.1.16 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 1.1.1.16 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 1.1.1.16 christos * LIMITED REMEDY. 98 1.1.1.16 christos * 99 1.1.1.16 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 1.1.1.16 christos * software or system incorporating such software without first obtaining any 101 1.1.1.16 christos * required license or other approval from the U. S. Department of Commerce or 102 1.1.1.16 christos * any other agency or department of the United States Government. In the 103 1.1.1.16 christos * event Licensee exports any such software from the United States or 104 1.1.1.16 christos * re-exports any such software from a foreign destination, Licensee shall 105 1.1.1.16 christos * ensure that the distribution and export/re-export of the software is in 106 1.1.1.16 christos * compliance with all laws, regulations, orders, or other restrictions of the 107 1.1.1.16 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 1.1.1.16 christos * any of its subsidiaries will export/re-export any technical data, process, 109 1.1.1.16 christos * software, or service, directly or indirectly, to any country for which the 110 1.1.1.16 christos * United States government or any agency thereof requires an export license, 111 1.1.1.16 christos * other governmental approval, or letter of assurance, without first obtaining 112 1.1.1.16 christos * such license, approval or letter. 113 1.1.1.16 christos * 114 1.1.1.16 christos ***************************************************************************** 115 1.1.1.16 christos * 116 1.1.1.16 christos * Alternatively, you may choose to be licensed under the terms of the 117 1.1.1.16 christos * following license: 118 1.1.1.16 christos * 119 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without 120 1.1.1.2 jruoho * modification, are permitted provided that the following conditions 121 1.1.1.2 jruoho * are met: 122 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright 123 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer, 124 1.1.1.2 jruoho * without modification. 125 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below 127 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon 128 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further 129 1.1.1.2 jruoho * binary redistribution. 130 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names 131 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived 132 1.1.1.2 jruoho * from this software without specific prior written permission. 133 1.1.1.2 jruoho * 134 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 1.1.1.12 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 1.1.1.16 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 1.1.1.16 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 1.1.1.16 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 1.1.1.16 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 1.1.1.16 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 1.1.1.16 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 1.1.1.16 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 1.1.1.16 christos * 146 1.1.1.16 christos * Alternatively, you may choose to be licensed under the terms of the 147 1.1.1.16 christos * GNU General Public License ("GPL") version 2 as published by the Free 148 1.1.1.16 christos * Software Foundation. 149 1.1.1.16 christos * 150 1.1.1.16 christos *****************************************************************************/ 151 1.1 jruoho 152 1.1 jruoho #include "acpi.h" 153 1.1 jruoho #include "accommon.h" 154 1.1 jruoho #include "acinterp.h" 155 1.1 jruoho #include "amlcode.h" 156 1.1 jruoho #include "acnamesp.h" 157 1.1.1.3 christos #include "acdispat.h" 158 1.1 jruoho 159 1.1 jruoho 160 1.1 jruoho #define _COMPONENT ACPI_EXECUTER 161 1.1 jruoho ACPI_MODULE_NAME ("exprep") 162 1.1 jruoho 163 1.1 jruoho /* Local prototypes */ 164 1.1 jruoho 165 1.1 jruoho static UINT32 166 1.1 jruoho AcpiExDecodeFieldAccess ( 167 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc, 168 1.1 jruoho UINT8 FieldFlags, 169 1.1 jruoho UINT32 *ReturnByteAlignment); 170 1.1 jruoho 171 1.1 jruoho 172 1.1 jruoho #ifdef ACPI_UNDER_DEVELOPMENT 173 1.1 jruoho 174 1.1 jruoho static UINT32 175 1.1 jruoho AcpiExGenerateAccess ( 176 1.1 jruoho UINT32 FieldBitOffset, 177 1.1 jruoho UINT32 FieldBitLength, 178 1.1 jruoho UINT32 RegionLength); 179 1.1 jruoho 180 1.1.1.6 christos 181 1.1 jruoho /******************************************************************************* 182 1.1 jruoho * 183 1.1 jruoho * FUNCTION: AcpiExGenerateAccess 184 1.1 jruoho * 185 1.1 jruoho * PARAMETERS: FieldBitOffset - Start of field within parent region/buffer 186 1.1 jruoho * FieldBitLength - Length of field in bits 187 1.1 jruoho * RegionLength - Length of parent in bytes 188 1.1 jruoho * 189 1.1 jruoho * RETURN: Field granularity (8, 16, 32 or 64) and 190 1.1 jruoho * ByteAlignment (1, 2, 3, or 4) 191 1.1 jruoho * 192 1.1 jruoho * DESCRIPTION: Generate an optimal access width for fields defined with the 193 1.1 jruoho * AnyAcc keyword. 194 1.1 jruoho * 195 1.1 jruoho * NOTE: Need to have the RegionLength in order to check for boundary 196 1.1.1.3 christos * conditions (end-of-region). However, the RegionLength is a deferred 197 1.1.1.3 christos * operation. Therefore, to complete this implementation, the generation 198 1.1 jruoho * of this access width must be deferred until the region length has 199 1.1 jruoho * been evaluated. 200 1.1 jruoho * 201 1.1 jruoho ******************************************************************************/ 202 1.1 jruoho 203 1.1 jruoho static UINT32 204 1.1 jruoho AcpiExGenerateAccess ( 205 1.1 jruoho UINT32 FieldBitOffset, 206 1.1 jruoho UINT32 FieldBitLength, 207 1.1 jruoho UINT32 RegionLength) 208 1.1 jruoho { 209 1.1 jruoho UINT32 FieldByteLength; 210 1.1 jruoho UINT32 FieldByteOffset; 211 1.1 jruoho UINT32 FieldByteEndOffset; 212 1.1 jruoho UINT32 AccessByteWidth; 213 1.1 jruoho UINT32 FieldStartOffset; 214 1.1 jruoho UINT32 FieldEndOffset; 215 1.1 jruoho UINT32 MinimumAccessWidth = 0xFFFFFFFF; 216 1.1 jruoho UINT32 MinimumAccesses = 0xFFFFFFFF; 217 1.1 jruoho UINT32 Accesses; 218 1.1 jruoho 219 1.1 jruoho 220 1.1 jruoho ACPI_FUNCTION_TRACE (ExGenerateAccess); 221 1.1 jruoho 222 1.1 jruoho 223 1.1 jruoho /* Round Field start offset and length to "minimal" byte boundaries */ 224 1.1 jruoho 225 1.1.1.6 christos FieldByteOffset = ACPI_DIV_8 ( 226 1.1.1.6 christos ACPI_ROUND_DOWN (FieldBitOffset, 8)); 227 1.1.1.6 christos 228 1.1.1.6 christos FieldByteEndOffset = ACPI_DIV_8 ( 229 1.1.1.6 christos ACPI_ROUND_UP (FieldBitLength + FieldBitOffset, 8)); 230 1.1.1.6 christos 231 1.1.1.6 christos FieldByteLength = FieldByteEndOffset - FieldByteOffset; 232 1.1 jruoho 233 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 234 1.1 jruoho "Bit length %u, Bit offset %u\n", 235 1.1 jruoho FieldBitLength, FieldBitOffset)); 236 1.1 jruoho 237 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 238 1.1 jruoho "Byte Length %u, Byte Offset %u, End Offset %u\n", 239 1.1 jruoho FieldByteLength, FieldByteOffset, FieldByteEndOffset)); 240 1.1 jruoho 241 1.1 jruoho /* 242 1.1 jruoho * Iterative search for the maximum access width that is both aligned 243 1.1 jruoho * and does not go beyond the end of the region 244 1.1 jruoho * 245 1.1 jruoho * Start at ByteAcc and work upwards to QwordAcc max. (1,2,4,8 bytes) 246 1.1 jruoho */ 247 1.1 jruoho for (AccessByteWidth = 1; AccessByteWidth <= 8; AccessByteWidth <<= 1) 248 1.1 jruoho { 249 1.1 jruoho /* 250 1.1 jruoho * 1) Round end offset up to next access boundary and make sure that 251 1.1 jruoho * this does not go beyond the end of the parent region. 252 1.1 jruoho * 2) When the Access width is greater than the FieldByteLength, we 253 1.1 jruoho * are done. (This does not optimize for the perfectly aligned 254 1.1 jruoho * case yet). 255 1.1 jruoho */ 256 1.1.1.6 christos if (ACPI_ROUND_UP (FieldByteEndOffset, AccessByteWidth) <= 257 1.1.1.6 christos RegionLength) 258 1.1 jruoho { 259 1.1 jruoho FieldStartOffset = 260 1.1 jruoho ACPI_ROUND_DOWN (FieldByteOffset, AccessByteWidth) / 261 1.1 jruoho AccessByteWidth; 262 1.1 jruoho 263 1.1 jruoho FieldEndOffset = 264 1.1 jruoho ACPI_ROUND_UP ((FieldByteLength + FieldByteOffset), 265 1.1 jruoho AccessByteWidth) / AccessByteWidth; 266 1.1 jruoho 267 1.1 jruoho Accesses = FieldEndOffset - FieldStartOffset; 268 1.1 jruoho 269 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 270 1.1 jruoho "AccessWidth %u end is within region\n", AccessByteWidth)); 271 1.1 jruoho 272 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 273 1.1 jruoho "Field Start %u, Field End %u -- requires %u accesses\n", 274 1.1 jruoho FieldStartOffset, FieldEndOffset, Accesses)); 275 1.1 jruoho 276 1.1 jruoho /* Single access is optimal */ 277 1.1 jruoho 278 1.1 jruoho if (Accesses <= 1) 279 1.1 jruoho { 280 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 281 1.1.1.6 christos "Entire field can be accessed " 282 1.1.1.6 christos "with one operation of size %u\n", 283 1.1 jruoho AccessByteWidth)); 284 1.1 jruoho return_VALUE (AccessByteWidth); 285 1.1 jruoho } 286 1.1 jruoho 287 1.1 jruoho /* 288 1.1 jruoho * Fits in the region, but requires more than one read/write. 289 1.1 jruoho * try the next wider access on next iteration 290 1.1 jruoho */ 291 1.1 jruoho if (Accesses < MinimumAccesses) 292 1.1 jruoho { 293 1.1.1.6 christos MinimumAccesses = Accesses; 294 1.1 jruoho MinimumAccessWidth = AccessByteWidth; 295 1.1 jruoho } 296 1.1 jruoho } 297 1.1 jruoho else 298 1.1 jruoho { 299 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 300 1.1.1.6 christos "AccessWidth %u end is NOT within region\n", 301 1.1.1.6 christos AccessByteWidth)); 302 1.1 jruoho if (AccessByteWidth == 1) 303 1.1 jruoho { 304 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 305 1.1 jruoho "Field goes beyond end-of-region!\n")); 306 1.1 jruoho 307 1.1 jruoho /* Field does not fit in the region at all */ 308 1.1 jruoho 309 1.1 jruoho return_VALUE (0); 310 1.1 jruoho } 311 1.1 jruoho 312 1.1 jruoho /* 313 1.1 jruoho * This width goes beyond the end-of-region, back off to 314 1.1 jruoho * previous access 315 1.1 jruoho */ 316 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 317 1.1 jruoho "Backing off to previous optimal access width of %u\n", 318 1.1 jruoho MinimumAccessWidth)); 319 1.1 jruoho return_VALUE (MinimumAccessWidth); 320 1.1 jruoho } 321 1.1 jruoho } 322 1.1 jruoho 323 1.1 jruoho /* 324 1.1 jruoho * Could not read/write field with one operation, 325 1.1 jruoho * just use max access width 326 1.1 jruoho */ 327 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 328 1.1 jruoho "Cannot access field in one operation, using width 8\n")); 329 1.1.1.6 christos 330 1.1 jruoho return_VALUE (8); 331 1.1 jruoho } 332 1.1 jruoho #endif /* ACPI_UNDER_DEVELOPMENT */ 333 1.1 jruoho 334 1.1 jruoho 335 1.1 jruoho /******************************************************************************* 336 1.1 jruoho * 337 1.1 jruoho * FUNCTION: AcpiExDecodeFieldAccess 338 1.1 jruoho * 339 1.1 jruoho * PARAMETERS: ObjDesc - Field object 340 1.1 jruoho * FieldFlags - Encoded fieldflags (contains access bits) 341 1.1 jruoho * ReturnByteAlignment - Where the byte alignment is returned 342 1.1 jruoho * 343 1.1 jruoho * RETURN: Field granularity (8, 16, 32 or 64) and 344 1.1 jruoho * ByteAlignment (1, 2, 3, or 4) 345 1.1 jruoho * 346 1.1 jruoho * DESCRIPTION: Decode the AccessType bits of a field definition. 347 1.1 jruoho * 348 1.1 jruoho ******************************************************************************/ 349 1.1 jruoho 350 1.1 jruoho static UINT32 351 1.1 jruoho AcpiExDecodeFieldAccess ( 352 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc, 353 1.1 jruoho UINT8 FieldFlags, 354 1.1 jruoho UINT32 *ReturnByteAlignment) 355 1.1 jruoho { 356 1.1 jruoho UINT32 Access; 357 1.1 jruoho UINT32 ByteAlignment; 358 1.1 jruoho UINT32 BitLength; 359 1.1 jruoho 360 1.1 jruoho 361 1.1 jruoho ACPI_FUNCTION_TRACE (ExDecodeFieldAccess); 362 1.1 jruoho 363 1.1 jruoho 364 1.1 jruoho Access = (FieldFlags & AML_FIELD_ACCESS_TYPE_MASK); 365 1.1 jruoho 366 1.1 jruoho switch (Access) 367 1.1 jruoho { 368 1.1 jruoho case AML_FIELD_ACCESS_ANY: 369 1.1 jruoho 370 1.1 jruoho #ifdef ACPI_UNDER_DEVELOPMENT 371 1.1 jruoho ByteAlignment = 372 1.1 jruoho AcpiExGenerateAccess (ObjDesc->CommonField.StartFieldBitOffset, 373 1.1 jruoho ObjDesc->CommonField.BitLength, 374 1.1 jruoho 0xFFFFFFFF /* Temp until we pass RegionLength as parameter */); 375 1.1 jruoho BitLength = ByteAlignment * 8; 376 1.1 jruoho #endif 377 1.1 jruoho 378 1.1 jruoho ByteAlignment = 1; 379 1.1 jruoho BitLength = 8; 380 1.1 jruoho break; 381 1.1 jruoho 382 1.1 jruoho case AML_FIELD_ACCESS_BYTE: 383 1.1 jruoho case AML_FIELD_ACCESS_BUFFER: /* ACPI 2.0 (SMBus Buffer) */ 384 1.1.1.3 christos 385 1.1 jruoho ByteAlignment = 1; 386 1.1 jruoho BitLength = 8; 387 1.1 jruoho break; 388 1.1 jruoho 389 1.1 jruoho case AML_FIELD_ACCESS_WORD: 390 1.1.1.3 christos 391 1.1 jruoho ByteAlignment = 2; 392 1.1 jruoho BitLength = 16; 393 1.1 jruoho break; 394 1.1 jruoho 395 1.1 jruoho case AML_FIELD_ACCESS_DWORD: 396 1.1.1.3 christos 397 1.1 jruoho ByteAlignment = 4; 398 1.1 jruoho BitLength = 32; 399 1.1 jruoho break; 400 1.1 jruoho 401 1.1 jruoho case AML_FIELD_ACCESS_QWORD: /* ACPI 2.0 */ 402 1.1.1.3 christos 403 1.1 jruoho ByteAlignment = 8; 404 1.1 jruoho BitLength = 64; 405 1.1 jruoho break; 406 1.1 jruoho 407 1.1 jruoho default: 408 1.1.1.3 christos 409 1.1 jruoho /* Invalid field access type */ 410 1.1 jruoho 411 1.1 jruoho ACPI_ERROR ((AE_INFO, 412 1.1 jruoho "Unknown field access type 0x%X", 413 1.1 jruoho Access)); 414 1.1.1.6 christos 415 1.1 jruoho return_UINT32 (0); 416 1.1 jruoho } 417 1.1 jruoho 418 1.1 jruoho if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD) 419 1.1 jruoho { 420 1.1 jruoho /* 421 1.1 jruoho * BufferField access can be on any byte boundary, so the 422 1.1 jruoho * ByteAlignment is always 1 byte -- regardless of any ByteAlignment 423 1.1 jruoho * implied by the field access type. 424 1.1 jruoho */ 425 1.1 jruoho ByteAlignment = 1; 426 1.1 jruoho } 427 1.1 jruoho 428 1.1 jruoho *ReturnByteAlignment = ByteAlignment; 429 1.1 jruoho return_UINT32 (BitLength); 430 1.1 jruoho } 431 1.1 jruoho 432 1.1 jruoho 433 1.1 jruoho /******************************************************************************* 434 1.1 jruoho * 435 1.1 jruoho * FUNCTION: AcpiExPrepCommonFieldObject 436 1.1 jruoho * 437 1.1 jruoho * PARAMETERS: ObjDesc - The field object 438 1.1 jruoho * FieldFlags - Access, LockRule, and UpdateRule. 439 1.1 jruoho * The format of a FieldFlag is described 440 1.1 jruoho * in the ACPI specification 441 1.1 jruoho * FieldAttribute - Special attributes (not used) 442 1.1 jruoho * FieldBitPosition - Field start position 443 1.1 jruoho * FieldBitLength - Field length in number of bits 444 1.1 jruoho * 445 1.1 jruoho * RETURN: Status 446 1.1 jruoho * 447 1.1 jruoho * DESCRIPTION: Initialize the areas of the field object that are common 448 1.1.1.3 christos * to the various types of fields. Note: This is very "sensitive" 449 1.1 jruoho * code because we are solving the general case for field 450 1.1 jruoho * alignment. 451 1.1 jruoho * 452 1.1 jruoho ******************************************************************************/ 453 1.1 jruoho 454 1.1 jruoho ACPI_STATUS 455 1.1 jruoho AcpiExPrepCommonFieldObject ( 456 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc, 457 1.1 jruoho UINT8 FieldFlags, 458 1.1 jruoho UINT8 FieldAttribute, 459 1.1 jruoho UINT32 FieldBitPosition, 460 1.1 jruoho UINT32 FieldBitLength) 461 1.1 jruoho { 462 1.1 jruoho UINT32 AccessBitWidth; 463 1.1 jruoho UINT32 ByteAlignment; 464 1.1 jruoho UINT32 NearestByteAddress; 465 1.1 jruoho 466 1.1 jruoho 467 1.1 jruoho ACPI_FUNCTION_TRACE (ExPrepCommonFieldObject); 468 1.1 jruoho 469 1.1 jruoho 470 1.1 jruoho /* 471 1.1 jruoho * Note: the structure being initialized is the 472 1.1 jruoho * ACPI_COMMON_FIELD_INFO; No structure fields outside of the common 473 1.1 jruoho * area are initialized by this procedure. 474 1.1 jruoho */ 475 1.1 jruoho ObjDesc->CommonField.FieldFlags = FieldFlags; 476 1.1 jruoho ObjDesc->CommonField.Attribute = FieldAttribute; 477 1.1 jruoho ObjDesc->CommonField.BitLength = FieldBitLength; 478 1.1 jruoho 479 1.1 jruoho /* 480 1.1.1.3 christos * Decode the access type so we can compute offsets. The access type gives 481 1.1 jruoho * two pieces of information - the width of each field access and the 482 1.1 jruoho * necessary ByteAlignment (address granularity) of the access. 483 1.1 jruoho * 484 1.1 jruoho * For AnyAcc, the AccessBitWidth is the largest width that is both 485 1.1 jruoho * necessary and possible in an attempt to access the whole field in one 486 1.1.1.3 christos * I/O operation. However, for AnyAcc, the ByteAlignment is always one 487 1.1 jruoho * byte. 488 1.1 jruoho * 489 1.1 jruoho * For all Buffer Fields, the ByteAlignment is always one byte. 490 1.1 jruoho * 491 1.1 jruoho * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is 492 1.1 jruoho * the same (equivalent) as the ByteAlignment. 493 1.1 jruoho */ 494 1.1.1.6 christos AccessBitWidth = AcpiExDecodeFieldAccess ( 495 1.1.1.6 christos ObjDesc, FieldFlags, &ByteAlignment); 496 1.1 jruoho if (!AccessBitWidth) 497 1.1 jruoho { 498 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_VALUE); 499 1.1 jruoho } 500 1.1 jruoho 501 1.1 jruoho /* Setup width (access granularity) fields (values are: 1, 2, 4, 8) */ 502 1.1 jruoho 503 1.1 jruoho ObjDesc->CommonField.AccessByteWidth = (UINT8) 504 1.1 jruoho ACPI_DIV_8 (AccessBitWidth); 505 1.1 jruoho 506 1.1 jruoho /* 507 1.1 jruoho * BaseByteOffset is the address of the start of the field within the 508 1.1.1.3 christos * region. It is the byte address of the first *datum* (field-width data 509 1.1 jruoho * unit) of the field. (i.e., the first datum that contains at least the 510 1.1 jruoho * first *bit* of the field.) 511 1.1 jruoho * 512 1.1 jruoho * Note: ByteAlignment is always either equal to the AccessBitWidth or 8 513 1.1 jruoho * (Byte access), and it defines the addressing granularity of the parent 514 1.1 jruoho * region or buffer. 515 1.1 jruoho */ 516 1.1 jruoho NearestByteAddress = 517 1.1 jruoho ACPI_ROUND_BITS_DOWN_TO_BYTES (FieldBitPosition); 518 1.1 jruoho ObjDesc->CommonField.BaseByteOffset = (UINT32) 519 1.1 jruoho ACPI_ROUND_DOWN (NearestByteAddress, ByteAlignment); 520 1.1 jruoho 521 1.1 jruoho /* 522 1.1 jruoho * StartFieldBitOffset is the offset of the first bit of the field within 523 1.1 jruoho * a field datum. 524 1.1 jruoho */ 525 1.1 jruoho ObjDesc->CommonField.StartFieldBitOffset = (UINT8) 526 1.1 jruoho (FieldBitPosition - ACPI_MUL_8 (ObjDesc->CommonField.BaseByteOffset)); 527 1.1 jruoho 528 1.1 jruoho return_ACPI_STATUS (AE_OK); 529 1.1 jruoho } 530 1.1 jruoho 531 1.1 jruoho 532 1.1 jruoho /******************************************************************************* 533 1.1 jruoho * 534 1.1 jruoho * FUNCTION: AcpiExPrepFieldValue 535 1.1 jruoho * 536 1.1 jruoho * PARAMETERS: Info - Contains all field creation info 537 1.1 jruoho * 538 1.1 jruoho * RETURN: Status 539 1.1 jruoho * 540 1.1.1.3 christos * DESCRIPTION: Construct an object of type ACPI_OPERAND_OBJECT with a 541 1.1.1.3 christos * subtype of DefField and connect it to the parent Node. 542 1.1 jruoho * 543 1.1 jruoho ******************************************************************************/ 544 1.1 jruoho 545 1.1 jruoho ACPI_STATUS 546 1.1 jruoho AcpiExPrepFieldValue ( 547 1.1 jruoho ACPI_CREATE_FIELD_INFO *Info) 548 1.1 jruoho { 549 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc; 550 1.1 jruoho ACPI_OPERAND_OBJECT *SecondDesc = NULL; 551 1.1 jruoho ACPI_STATUS Status; 552 1.1 jruoho UINT32 AccessByteWidth; 553 1.1 jruoho UINT32 Type; 554 1.1 jruoho 555 1.1 jruoho 556 1.1 jruoho ACPI_FUNCTION_TRACE (ExPrepFieldValue); 557 1.1 jruoho 558 1.1 jruoho 559 1.1 jruoho /* Parameter validation */ 560 1.1 jruoho 561 1.1 jruoho if (Info->FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD) 562 1.1 jruoho { 563 1.1 jruoho if (!Info->RegionNode) 564 1.1 jruoho { 565 1.1 jruoho ACPI_ERROR ((AE_INFO, "Null RegionNode")); 566 1.1 jruoho return_ACPI_STATUS (AE_AML_NO_OPERAND); 567 1.1 jruoho } 568 1.1 jruoho 569 1.1 jruoho Type = AcpiNsGetType (Info->RegionNode); 570 1.1 jruoho if (Type != ACPI_TYPE_REGION) 571 1.1 jruoho { 572 1.1 jruoho ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)", 573 1.1 jruoho Type, AcpiUtGetTypeName (Type))); 574 1.1 jruoho 575 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 576 1.1 jruoho } 577 1.1 jruoho } 578 1.1 jruoho 579 1.1 jruoho /* Allocate a new field object */ 580 1.1 jruoho 581 1.1 jruoho ObjDesc = AcpiUtCreateInternalObject (Info->FieldType); 582 1.1 jruoho if (!ObjDesc) 583 1.1 jruoho { 584 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY); 585 1.1 jruoho } 586 1.1 jruoho 587 1.1 jruoho /* Initialize areas of the object that are common to all fields */ 588 1.1 jruoho 589 1.1 jruoho ObjDesc->CommonField.Node = Info->FieldNode; 590 1.1 jruoho Status = AcpiExPrepCommonFieldObject (ObjDesc, 591 1.1.1.6 christos Info->FieldFlags, Info->Attribute, 592 1.1.1.6 christos Info->FieldBitPosition, Info->FieldBitLength); 593 1.1 jruoho if (ACPI_FAILURE (Status)) 594 1.1 jruoho { 595 1.1 jruoho AcpiUtDeleteObjectDesc (ObjDesc); 596 1.1 jruoho return_ACPI_STATUS (Status); 597 1.1 jruoho } 598 1.1 jruoho 599 1.1 jruoho /* Initialize areas of the object that are specific to the field type */ 600 1.1 jruoho 601 1.1 jruoho switch (Info->FieldType) 602 1.1 jruoho { 603 1.1 jruoho case ACPI_TYPE_LOCAL_REGION_FIELD: 604 1.1 jruoho 605 1.1 jruoho ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (Info->RegionNode); 606 1.1 jruoho 607 1.1.1.3 christos /* Fields specific to GenericSerialBus fields */ 608 1.1.1.3 christos 609 1.1.1.3 christos ObjDesc->Field.AccessLength = Info->AccessLength; 610 1.1.1.3 christos 611 1.1.1.3 christos if (Info->ConnectionNode) 612 1.1.1.3 christos { 613 1.1.1.3 christos SecondDesc = Info->ConnectionNode->Object; 614 1.1.1.15 christos if (SecondDesc == NULL) 615 1.1.1.15 christos { 616 1.1.1.15 christos break; 617 1.1.1.15 christos } 618 1.1.1.3 christos if (!(SecondDesc->Common.Flags & AOPOBJ_DATA_VALID)) 619 1.1.1.3 christos { 620 1.1.1.3 christos Status = AcpiDsGetBufferArguments (SecondDesc); 621 1.1.1.3 christos if (ACPI_FAILURE (Status)) 622 1.1.1.3 christos { 623 1.1.1.3 christos AcpiUtDeleteObjectDesc (ObjDesc); 624 1.1.1.3 christos return_ACPI_STATUS (Status); 625 1.1.1.3 christos } 626 1.1.1.3 christos } 627 1.1.1.3 christos 628 1.1.1.6 christos ObjDesc->Field.ResourceBuffer = 629 1.1.1.6 christos SecondDesc->Buffer.Pointer; 630 1.1.1.6 christos ObjDesc->Field.ResourceLength = 631 1.1.1.6 christos (UINT16) SecondDesc->Buffer.Length; 632 1.1.1.3 christos } 633 1.1.1.3 christos else if (Info->ResourceBuffer) 634 1.1.1.3 christos { 635 1.1.1.3 christos ObjDesc->Field.ResourceBuffer = Info->ResourceBuffer; 636 1.1.1.3 christos ObjDesc->Field.ResourceLength = Info->ResourceLength; 637 1.1.1.3 christos } 638 1.1.1.3 christos 639 1.1.1.4 christos ObjDesc->Field.PinNumberIndex = Info->PinNumberIndex; 640 1.1.1.4 christos 641 1.1 jruoho /* Allow full data read from EC address space */ 642 1.1 jruoho 643 1.1 jruoho if ((ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) && 644 1.1 jruoho (ObjDesc->CommonField.BitLength > 8)) 645 1.1 jruoho { 646 1.1 jruoho AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES ( 647 1.1 jruoho ObjDesc->CommonField.BitLength); 648 1.1 jruoho 649 1.1 jruoho /* Maximum byte width supported is 255 */ 650 1.1 jruoho 651 1.1 jruoho if (AccessByteWidth < 256) 652 1.1 jruoho { 653 1.1.1.6 christos ObjDesc->CommonField.AccessByteWidth = 654 1.1.1.6 christos (UINT8) AccessByteWidth; 655 1.1 jruoho } 656 1.1 jruoho } 657 1.1 jruoho 658 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 659 1.1 jruoho "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n", 660 1.1.1.6 christos ObjDesc->Field.StartFieldBitOffset, 661 1.1.1.6 christos ObjDesc->Field.BaseByteOffset, 662 1.1.1.6 christos ObjDesc->Field.AccessByteWidth, 663 1.1.1.6 christos ObjDesc->Field.RegionObj)); 664 1.1 jruoho break; 665 1.1 jruoho 666 1.1 jruoho case ACPI_TYPE_LOCAL_BANK_FIELD: 667 1.1 jruoho 668 1.1 jruoho ObjDesc->BankField.Value = Info->BankValue; 669 1.1 jruoho ObjDesc->BankField.RegionObj = 670 1.1 jruoho AcpiNsGetAttachedObject (Info->RegionNode); 671 1.1 jruoho ObjDesc->BankField.BankObj = 672 1.1 jruoho AcpiNsGetAttachedObject (Info->RegisterNode); 673 1.1 jruoho 674 1.1 jruoho /* An additional reference for the attached objects */ 675 1.1 jruoho 676 1.1 jruoho AcpiUtAddReference (ObjDesc->BankField.RegionObj); 677 1.1 jruoho AcpiUtAddReference (ObjDesc->BankField.BankObj); 678 1.1 jruoho 679 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 680 1.1 jruoho "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n", 681 1.1 jruoho ObjDesc->BankField.StartFieldBitOffset, 682 1.1 jruoho ObjDesc->BankField.BaseByteOffset, 683 1.1 jruoho ObjDesc->Field.AccessByteWidth, 684 1.1 jruoho ObjDesc->BankField.RegionObj, 685 1.1 jruoho ObjDesc->BankField.BankObj)); 686 1.1 jruoho 687 1.1 jruoho /* 688 1.1 jruoho * Remember location in AML stream of the field unit 689 1.1 jruoho * opcode and operands -- since the BankValue 690 1.1 jruoho * operands must be evaluated. 691 1.1 jruoho */ 692 1.1 jruoho SecondDesc = ObjDesc->Common.NextObject; 693 1.1 jruoho SecondDesc->Extra.AmlStart = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, 694 1.1 jruoho Info->DataRegisterNode)->Named.Data; 695 1.1 jruoho SecondDesc->Extra.AmlLength = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, 696 1.1 jruoho Info->DataRegisterNode)->Named.Length; 697 1.1 jruoho 698 1.1 jruoho break; 699 1.1 jruoho 700 1.1 jruoho case ACPI_TYPE_LOCAL_INDEX_FIELD: 701 1.1 jruoho 702 1.1 jruoho /* Get the Index and Data registers */ 703 1.1 jruoho 704 1.1 jruoho ObjDesc->IndexField.IndexObj = 705 1.1 jruoho AcpiNsGetAttachedObject (Info->RegisterNode); 706 1.1 jruoho ObjDesc->IndexField.DataObj = 707 1.1 jruoho AcpiNsGetAttachedObject (Info->DataRegisterNode); 708 1.1 jruoho 709 1.1 jruoho if (!ObjDesc->IndexField.DataObj || !ObjDesc->IndexField.IndexObj) 710 1.1 jruoho { 711 1.1 jruoho ACPI_ERROR ((AE_INFO, "Null Index Object during field prep")); 712 1.1 jruoho AcpiUtDeleteObjectDesc (ObjDesc); 713 1.1 jruoho return_ACPI_STATUS (AE_AML_INTERNAL); 714 1.1 jruoho } 715 1.1 jruoho 716 1.1 jruoho /* An additional reference for the attached objects */ 717 1.1 jruoho 718 1.1 jruoho AcpiUtAddReference (ObjDesc->IndexField.DataObj); 719 1.1 jruoho AcpiUtAddReference (ObjDesc->IndexField.IndexObj); 720 1.1 jruoho 721 1.1 jruoho /* 722 1.1 jruoho * April 2006: Changed to match MS behavior 723 1.1 jruoho * 724 1.1 jruoho * The value written to the Index register is the byte offset of the 725 1.1 jruoho * target field in units of the granularity of the IndexField 726 1.1 jruoho * 727 1.1 jruoho * Previously, the value was calculated as an index in terms of the 728 1.1 jruoho * width of the Data register, as below: 729 1.1 jruoho * 730 1.1 jruoho * ObjDesc->IndexField.Value = (UINT32) 731 1.1 jruoho * (Info->FieldBitPosition / ACPI_MUL_8 ( 732 1.1 jruoho * ObjDesc->Field.AccessByteWidth)); 733 1.1 jruoho * 734 1.1 jruoho * February 2006: Tried value as a byte offset: 735 1.1 jruoho * ObjDesc->IndexField.Value = (UINT32) 736 1.1 jruoho * ACPI_DIV_8 (Info->FieldBitPosition); 737 1.1 jruoho */ 738 1.1 jruoho ObjDesc->IndexField.Value = (UINT32) ACPI_ROUND_DOWN ( 739 1.1 jruoho ACPI_DIV_8 (Info->FieldBitPosition), 740 1.1 jruoho ObjDesc->IndexField.AccessByteWidth); 741 1.1 jruoho 742 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 743 1.1.1.6 christos "IndexField: BitOff %X, Off %X, Value %X, " 744 1.1.1.6 christos "Gran %X, Index %p, Data %p\n", 745 1.1 jruoho ObjDesc->IndexField.StartFieldBitOffset, 746 1.1 jruoho ObjDesc->IndexField.BaseByteOffset, 747 1.1 jruoho ObjDesc->IndexField.Value, 748 1.1 jruoho ObjDesc->Field.AccessByteWidth, 749 1.1 jruoho ObjDesc->IndexField.IndexObj, 750 1.1 jruoho ObjDesc->IndexField.DataObj)); 751 1.1 jruoho break; 752 1.1 jruoho 753 1.1 jruoho default: 754 1.1.1.3 christos 755 1.1 jruoho /* No other types should get here */ 756 1.1.1.3 christos 757 1.1 jruoho break; 758 1.1 jruoho } 759 1.1 jruoho 760 1.1 jruoho /* 761 1.1 jruoho * Store the constructed descriptor (ObjDesc) into the parent Node, 762 1.1 jruoho * preserving the current type of that NamedObj. 763 1.1 jruoho */ 764 1.1.1.6 christos Status = AcpiNsAttachObject ( 765 1.1.1.6 christos Info->FieldNode, ObjDesc, AcpiNsGetType (Info->FieldNode)); 766 1.1 jruoho 767 1.1.1.6 christos ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 768 1.1.1.6 christos "Set NamedObj %p [%4.4s], ObjDesc %p\n", 769 1.1 jruoho Info->FieldNode, AcpiUtGetNodeName (Info->FieldNode), ObjDesc)); 770 1.1 jruoho 771 1.1 jruoho /* Remove local reference to the object */ 772 1.1 jruoho 773 1.1 jruoho AcpiUtRemoveReference (ObjDesc); 774 1.1 jruoho return_ACPI_STATUS (Status); 775 1.1 jruoho } 776