1a159c266SJung-uk Kim /****************************************************************************** 2a159c266SJung-uk Kim * 3a159c266SJung-uk Kim * Module Name: nspredef - Validation of ACPI predefined methods and objects 4a159c266SJung-uk Kim * 5a159c266SJung-uk Kim *****************************************************************************/ 6a159c266SJung-uk Kim 70d84335fSJung-uk Kim /****************************************************************************** 80d84335fSJung-uk Kim * 90d84335fSJung-uk Kim * 1. Copyright Notice 100d84335fSJung-uk Kim * 11*804fe266SJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp. 12a159c266SJung-uk Kim * All rights reserved. 13a159c266SJung-uk Kim * 140d84335fSJung-uk Kim * 2. License 150d84335fSJung-uk Kim * 160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property 170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided 180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual 190d84335fSJung-uk Kim * property rights. 200d84335fSJung-uk Kim * 210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an 230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy, 250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered 260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and 270d84335fSJung-uk Kim * 280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel 300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell, 310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof 320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright 330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions 340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right 350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise; 360d84335fSJung-uk Kim * 370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following 380d84335fSJung-uk Kim * conditions are met: 390d84335fSJung-uk Kim * 400d84335fSJung-uk Kim * 3. Conditions 410d84335fSJung-uk Kim * 420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include 450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions, 460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition, 470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to 480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered 490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the 500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee 510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived, 520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code. 530d84335fSJung-uk Kim * 540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must 570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the 580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In 590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any 600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the 610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual 620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and 630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may 640d84335fSJung-uk Kim * make. 650d84335fSJung-uk Kim * 660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any 670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the 680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance 690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the 700d84335fSJung-uk Kim * distribution. 710d84335fSJung-uk Kim * 720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original 730d84335fSJung-uk Kim * Intel Code. 740d84335fSJung-uk Kim * 750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or 770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code 780d84335fSJung-uk Kim * without prior written authorization from Intel. 790d84335fSJung-uk Kim * 800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance 810d84335fSJung-uk Kim * 820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 880d84335fSJung-uk Kim * PARTICULAR PURPOSE. 890d84335fSJung-uk Kim * 900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 970d84335fSJung-uk Kim * LIMITED REMEDY. 980d84335fSJung-uk Kim * 990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this 1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any 1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or 1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the 1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or 1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall 1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in 1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the 1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process, 1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the 1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license, 1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining 1120d84335fSJung-uk Kim * such license, approval or letter. 1130d84335fSJung-uk Kim * 1140d84335fSJung-uk Kim ***************************************************************************** 1150d84335fSJung-uk Kim * 1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 1170d84335fSJung-uk Kim * following license: 1180d84335fSJung-uk Kim * 119a159c266SJung-uk Kim * Redistribution and use in source and binary forms, with or without 120a159c266SJung-uk Kim * modification, are permitted provided that the following conditions 121a159c266SJung-uk Kim * are met: 122a159c266SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 123a159c266SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 124a159c266SJung-uk Kim * without modification. 125a159c266SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126a159c266SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 127a159c266SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 128a159c266SJung-uk Kim * including a substantially similar Disclaimer requirement for further 129a159c266SJung-uk Kim * binary redistribution. 130a159c266SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 131a159c266SJung-uk Kim * of any contributors may be used to endorse or promote products derived 132a159c266SJung-uk Kim * from this software without specific prior written permission. 133a159c266SJung-uk Kim * 1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1450d84335fSJung-uk Kim * 1460d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 147a159c266SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 148a159c266SJung-uk Kim * Software Foundation. 149a159c266SJung-uk Kim * 1500d84335fSJung-uk Kim *****************************************************************************/ 151a159c266SJung-uk Kim 152a159c266SJung-uk Kim #define ACPI_CREATE_PREDEFINED_TABLE 153a159c266SJung-uk Kim 154a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h> 155a159c266SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h> 156a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h> 157a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acpredef.h> 158a159c266SJung-uk Kim 159a159c266SJung-uk Kim 160a159c266SJung-uk Kim #define _COMPONENT ACPI_NAMESPACE 161a159c266SJung-uk Kim ACPI_MODULE_NAME ("nspredef") 162a159c266SJung-uk Kim 163a159c266SJung-uk Kim 164a159c266SJung-uk Kim /******************************************************************************* 165a159c266SJung-uk Kim * 166a159c266SJung-uk Kim * This module validates predefined ACPI objects that appear in the namespace, 167a159c266SJung-uk Kim * at the time they are evaluated (via AcpiEvaluateObject). The purpose of this 168a159c266SJung-uk Kim * validation is to detect problems with BIOS-exposed predefined ACPI objects 169a159c266SJung-uk Kim * before the results are returned to the ACPI-related drivers. 170a159c266SJung-uk Kim * 171a159c266SJung-uk Kim * There are several areas that are validated: 172a159c266SJung-uk Kim * 173a159c266SJung-uk Kim * 1) The number of input arguments as defined by the method/object in the 174a159c266SJung-uk Kim * ASL is validated against the ACPI specification. 175a159c266SJung-uk Kim * 2) The type of the return object (if any) is validated against the ACPI 176a159c266SJung-uk Kim * specification. 177a159c266SJung-uk Kim * 3) For returned package objects, the count of package elements is 178a159c266SJung-uk Kim * validated, as well as the type of each package element. Nested 179a159c266SJung-uk Kim * packages are supported. 180a159c266SJung-uk Kim * 181a159c266SJung-uk Kim * For any problems found, a warning message is issued. 182a159c266SJung-uk Kim * 183a159c266SJung-uk Kim ******************************************************************************/ 184a159c266SJung-uk Kim 185a159c266SJung-uk Kim 186a159c266SJung-uk Kim /* Local prototypes */ 187a159c266SJung-uk Kim 188a159c266SJung-uk Kim static ACPI_STATUS 189a159c266SJung-uk Kim AcpiNsCheckReference ( 190895f26a9SJung-uk Kim ACPI_EVALUATE_INFO *Info, 191a159c266SJung-uk Kim ACPI_OPERAND_OBJECT *ReturnObject); 192a159c266SJung-uk Kim 1939c48c75eSJung-uk Kim static UINT32 1949c48c75eSJung-uk Kim AcpiNsGetBitmappedType ( 1959c48c75eSJung-uk Kim ACPI_OPERAND_OBJECT *ReturnObject); 1969c48c75eSJung-uk Kim 1979c48c75eSJung-uk Kim 198a159c266SJung-uk Kim /******************************************************************************* 199a159c266SJung-uk Kim * 200895f26a9SJung-uk Kim * FUNCTION: AcpiNsCheckReturnValue 201a159c266SJung-uk Kim * 202a159c266SJung-uk Kim * PARAMETERS: Node - Namespace node for the method/object 203895f26a9SJung-uk Kim * Info - Method execution information block 204a159c266SJung-uk Kim * UserParamCount - Number of parameters actually passed 205a159c266SJung-uk Kim * ReturnStatus - Status from the object evaluation 206a159c266SJung-uk Kim * ReturnObjectPtr - Pointer to the object returned from the 207a159c266SJung-uk Kim * evaluation of a method or object 208a159c266SJung-uk Kim * 209a159c266SJung-uk Kim * RETURN: Status 210a159c266SJung-uk Kim * 211895f26a9SJung-uk Kim * DESCRIPTION: Check the value returned from a predefined name. 212a159c266SJung-uk Kim * 213a159c266SJung-uk Kim ******************************************************************************/ 214a159c266SJung-uk Kim 215a159c266SJung-uk Kim ACPI_STATUS 216895f26a9SJung-uk Kim AcpiNsCheckReturnValue ( 217a159c266SJung-uk Kim ACPI_NAMESPACE_NODE *Node, 218895f26a9SJung-uk Kim ACPI_EVALUATE_INFO *Info, 219a159c266SJung-uk Kim UINT32 UserParamCount, 220a159c266SJung-uk Kim ACPI_STATUS ReturnStatus, 221a159c266SJung-uk Kim ACPI_OPERAND_OBJECT **ReturnObjectPtr) 222a159c266SJung-uk Kim { 223895f26a9SJung-uk Kim ACPI_STATUS Status; 224a159c266SJung-uk Kim const ACPI_PREDEFINED_INFO *Predefined; 225a159c266SJung-uk Kim 226fbde3477SJung-uk Kim ACPI_FUNCTION_TRACE (NsCheckReturnValue); 227a159c266SJung-uk Kim 228a159c266SJung-uk Kim /* If not a predefined name, we cannot validate the return object */ 229a159c266SJung-uk Kim 230895f26a9SJung-uk Kim Predefined = Info->Predefined; 231a159c266SJung-uk Kim if (!Predefined) 232a159c266SJung-uk Kim { 233fbde3477SJung-uk Kim return_ACPI_STATUS (AE_OK); 234a159c266SJung-uk Kim } 235a159c266SJung-uk Kim 236a159c266SJung-uk Kim /* 237a159c266SJung-uk Kim * If the method failed or did not actually return an object, we cannot 238a159c266SJung-uk Kim * validate the return object 239a159c266SJung-uk Kim */ 240895f26a9SJung-uk Kim if ((ReturnStatus != AE_OK) && 241895f26a9SJung-uk Kim (ReturnStatus != AE_CTRL_RETURN_VALUE)) 242a159c266SJung-uk Kim { 243fbde3477SJung-uk Kim return_ACPI_STATUS (AE_OK); 244a159c266SJung-uk Kim } 245a159c266SJung-uk Kim 246a159c266SJung-uk Kim /* 247a159c266SJung-uk Kim * Return value validation and possible repair. 248a159c266SJung-uk Kim * 249a159c266SJung-uk Kim * 1) Don't perform return value validation/repair if this feature 250a159c266SJung-uk Kim * has been disabled via a global option. 251a159c266SJung-uk Kim * 252a159c266SJung-uk Kim * 2) We have a return value, but if one wasn't expected, just exit, 253a159c266SJung-uk Kim * this is not a problem. For example, if the "Implicit Return" 254a159c266SJung-uk Kim * feature is enabled, methods will always return a value. 255a159c266SJung-uk Kim * 256a159c266SJung-uk Kim * 3) If the return value can be of any type, then we cannot perform 257a159c266SJung-uk Kim * any validation, just exit. 258a159c266SJung-uk Kim */ 259a159c266SJung-uk Kim if (AcpiGbl_DisableAutoRepair || 260a159c266SJung-uk Kim (!Predefined->Info.ExpectedBtypes) || 261a159c266SJung-uk Kim (Predefined->Info.ExpectedBtypes == ACPI_RTYPE_ALL)) 262a159c266SJung-uk Kim { 263fbde3477SJung-uk Kim return_ACPI_STATUS (AE_OK); 264a159c266SJung-uk Kim } 265a159c266SJung-uk Kim 266a159c266SJung-uk Kim /* 267a159c266SJung-uk Kim * Check that the type of the main return object is what is expected 268a159c266SJung-uk Kim * for this predefined name 269a159c266SJung-uk Kim */ 270895f26a9SJung-uk Kim Status = AcpiNsCheckObjectType (Info, ReturnObjectPtr, 271a159c266SJung-uk Kim Predefined->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT); 272a159c266SJung-uk Kim if (ACPI_FAILURE (Status)) 273a159c266SJung-uk Kim { 274a159c266SJung-uk Kim goto Exit; 275a159c266SJung-uk Kim } 276a159c266SJung-uk Kim 277a159c266SJung-uk Kim /* 278bf6fac21SJung-uk Kim * 279bf6fac21SJung-uk Kim * 4) If there is no return value and it is optional, just return 280bf6fac21SJung-uk Kim * AE_OK (_WAK). 281bf6fac21SJung-uk Kim */ 282bf6fac21SJung-uk Kim if (!(*ReturnObjectPtr)) 283bf6fac21SJung-uk Kim { 284bf6fac21SJung-uk Kim goto Exit; 285bf6fac21SJung-uk Kim } 286bf6fac21SJung-uk Kim 287bf6fac21SJung-uk Kim /* 288a159c266SJung-uk Kim * For returned Package objects, check the type of all sub-objects. 289a159c266SJung-uk Kim * Note: Package may have been newly created by call above. 290a159c266SJung-uk Kim */ 291a159c266SJung-uk Kim if ((*ReturnObjectPtr)->Common.Type == ACPI_TYPE_PACKAGE) 292a159c266SJung-uk Kim { 293895f26a9SJung-uk Kim Info->ParentPackage = *ReturnObjectPtr; 294895f26a9SJung-uk Kim Status = AcpiNsCheckPackage (Info, ReturnObjectPtr); 295a159c266SJung-uk Kim if (ACPI_FAILURE (Status)) 296a159c266SJung-uk Kim { 297a9d8d09cSJung-uk Kim /* We might be able to fix some errors */ 298a9d8d09cSJung-uk Kim 299a9d8d09cSJung-uk Kim if ((Status != AE_AML_OPERAND_TYPE) && 300a9d8d09cSJung-uk Kim (Status != AE_AML_OPERAND_VALUE)) 301a9d8d09cSJung-uk Kim { 302a159c266SJung-uk Kim goto Exit; 303a159c266SJung-uk Kim } 304a159c266SJung-uk Kim } 305a9d8d09cSJung-uk Kim } 306a159c266SJung-uk Kim 307a159c266SJung-uk Kim /* 308a159c266SJung-uk Kim * The return object was OK, or it was successfully repaired above. 309a159c266SJung-uk Kim * Now make some additional checks such as verifying that package 310a159c266SJung-uk Kim * objects are sorted correctly (if required) or buffer objects have 311a159c266SJung-uk Kim * the correct data width (bytes vs. dwords). These repairs are 312a159c266SJung-uk Kim * performed on a per-name basis, i.e., the code is specific to 313a159c266SJung-uk Kim * particular predefined names. 314a159c266SJung-uk Kim */ 315895f26a9SJung-uk Kim Status = AcpiNsComplexRepairs (Info, Node, Status, ReturnObjectPtr); 316a159c266SJung-uk Kim 317a159c266SJung-uk Kim Exit: 318a159c266SJung-uk Kim /* 319a159c266SJung-uk Kim * If the object validation failed or if we successfully repaired one 320a159c266SJung-uk Kim * or more objects, mark the parent node to suppress further warning 321a159c266SJung-uk Kim * messages during the next evaluation of the same method/object. 322a159c266SJung-uk Kim */ 323895f26a9SJung-uk Kim if (ACPI_FAILURE (Status) || 324895f26a9SJung-uk Kim (Info->ReturnFlags & ACPI_OBJECT_REPAIRED)) 325a159c266SJung-uk Kim { 326a159c266SJung-uk Kim Node->Flags |= ANOBJ_EVALUATED; 327a159c266SJung-uk Kim } 328a159c266SJung-uk Kim 329fbde3477SJung-uk Kim return_ACPI_STATUS (Status); 330a159c266SJung-uk Kim } 331a159c266SJung-uk Kim 332a159c266SJung-uk Kim 333a159c266SJung-uk Kim /******************************************************************************* 334a159c266SJung-uk Kim * 335a159c266SJung-uk Kim * FUNCTION: AcpiNsCheckObjectType 336a159c266SJung-uk Kim * 337895f26a9SJung-uk Kim * PARAMETERS: Info - Method execution information block 338a159c266SJung-uk Kim * ReturnObjectPtr - Pointer to the object returned from the 339a159c266SJung-uk Kim * evaluation of a method or object 340a159c266SJung-uk Kim * ExpectedBtypes - Bitmap of expected return type(s) 341a159c266SJung-uk Kim * PackageIndex - Index of object within parent package (if 342a159c266SJung-uk Kim * applicable - ACPI_NOT_PACKAGE_ELEMENT 343a159c266SJung-uk Kim * otherwise) 344a159c266SJung-uk Kim * 345a159c266SJung-uk Kim * RETURN: Status 346a159c266SJung-uk Kim * 347a159c266SJung-uk Kim * DESCRIPTION: Check the type of the return object against the expected object 348a159c266SJung-uk Kim * type(s). Use of Btype allows multiple expected object types. 349a159c266SJung-uk Kim * 350a159c266SJung-uk Kim ******************************************************************************/ 351a159c266SJung-uk Kim 352efcc2a30SJung-uk Kim ACPI_STATUS 353a159c266SJung-uk Kim AcpiNsCheckObjectType ( 354895f26a9SJung-uk Kim ACPI_EVALUATE_INFO *Info, 355a159c266SJung-uk Kim ACPI_OPERAND_OBJECT **ReturnObjectPtr, 356a159c266SJung-uk Kim UINT32 ExpectedBtypes, 357a159c266SJung-uk Kim UINT32 PackageIndex) 358a159c266SJung-uk Kim { 359a159c266SJung-uk Kim ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr; 360a159c266SJung-uk Kim ACPI_STATUS Status = AE_OK; 361f8146b88SJung-uk Kim char TypeBuffer[96]; /* Room for 10 types */ 362a159c266SJung-uk Kim 363a159c266SJung-uk Kim 364a159c266SJung-uk Kim /* A Namespace node should not get here, but make sure */ 365a159c266SJung-uk Kim 3669c48c75eSJung-uk Kim if (ReturnObject && 3679c48c75eSJung-uk Kim ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED) 368a159c266SJung-uk Kim { 369895f26a9SJung-uk Kim ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, 370a159c266SJung-uk Kim "Invalid return type - Found a Namespace node [%4.4s] type %s", 371a159c266SJung-uk Kim ReturnObject->Node.Name.Ascii, 372a159c266SJung-uk Kim AcpiUtGetTypeName (ReturnObject->Node.Type))); 373a159c266SJung-uk Kim return (AE_AML_OPERAND_TYPE); 374a159c266SJung-uk Kim } 375a159c266SJung-uk Kim 376a159c266SJung-uk Kim /* 377a159c266SJung-uk Kim * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type. 378a159c266SJung-uk Kim * The bitmapped type allows multiple possible return types. 379a159c266SJung-uk Kim * 380a159c266SJung-uk Kim * Note, the cases below must handle all of the possible types returned 381a159c266SJung-uk Kim * from all of the predefined names (including elements of returned 382a159c266SJung-uk Kim * packages) 383a159c266SJung-uk Kim */ 384895f26a9SJung-uk Kim Info->ReturnBtype = AcpiNsGetBitmappedType (ReturnObject); 385895f26a9SJung-uk Kim if (Info->ReturnBtype == ACPI_RTYPE_ANY) 386a159c266SJung-uk Kim { 387a159c266SJung-uk Kim /* Not one of the supported objects, must be incorrect */ 388a159c266SJung-uk Kim goto TypeErrorExit; 389a159c266SJung-uk Kim } 390a159c266SJung-uk Kim 391a159c266SJung-uk Kim /* For reference objects, check that the reference type is correct */ 392a159c266SJung-uk Kim 393895f26a9SJung-uk Kim if ((Info->ReturnBtype & ExpectedBtypes) == ACPI_RTYPE_REFERENCE) 394a159c266SJung-uk Kim { 395895f26a9SJung-uk Kim Status = AcpiNsCheckReference (Info, ReturnObject); 396a159c266SJung-uk Kim return (Status); 397a159c266SJung-uk Kim } 398a159c266SJung-uk Kim 3999c48c75eSJung-uk Kim /* Attempt simple repair of the returned object if necessary */ 400a159c266SJung-uk Kim 401895f26a9SJung-uk Kim Status = AcpiNsSimpleRepair (Info, ExpectedBtypes, 402a159c266SJung-uk Kim PackageIndex, ReturnObjectPtr); 403895f26a9SJung-uk Kim if (ACPI_SUCCESS (Status)) 404895f26a9SJung-uk Kim { 405895f26a9SJung-uk Kim return (AE_OK); /* Successful repair */ 406895f26a9SJung-uk Kim } 407a159c266SJung-uk Kim 408a159c266SJung-uk Kim 409a159c266SJung-uk Kim TypeErrorExit: 410a159c266SJung-uk Kim 411a159c266SJung-uk Kim /* Create a string with all expected types for this predefined object */ 412a159c266SJung-uk Kim 4139c7c683cSJung-uk Kim AcpiUtGetExpectedReturnTypes (TypeBuffer, ExpectedBtypes); 414a159c266SJung-uk Kim 415bf6fac21SJung-uk Kim if (!ReturnObject) 416bf6fac21SJung-uk Kim { 417bf6fac21SJung-uk Kim ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, 418bf6fac21SJung-uk Kim "Expected return object of type %s", 419bf6fac21SJung-uk Kim TypeBuffer)); 420bf6fac21SJung-uk Kim } 421bf6fac21SJung-uk Kim else if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT) 422a159c266SJung-uk Kim { 423895f26a9SJung-uk Kim ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, 424a159c266SJung-uk Kim "Return type mismatch - found %s, expected %s", 425a159c266SJung-uk Kim AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer)); 426a159c266SJung-uk Kim } 427a159c266SJung-uk Kim else 428a159c266SJung-uk Kim { 429895f26a9SJung-uk Kim ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, 430a159c266SJung-uk Kim "Return Package type mismatch at index %u - " 431a159c266SJung-uk Kim "found %s, expected %s", PackageIndex, 432a159c266SJung-uk Kim AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer)); 433a159c266SJung-uk Kim } 434a159c266SJung-uk Kim 435a159c266SJung-uk Kim return (AE_AML_OPERAND_TYPE); 436a159c266SJung-uk Kim } 437a159c266SJung-uk Kim 438a159c266SJung-uk Kim 439a159c266SJung-uk Kim /******************************************************************************* 440a159c266SJung-uk Kim * 441a159c266SJung-uk Kim * FUNCTION: AcpiNsCheckReference 442a159c266SJung-uk Kim * 443895f26a9SJung-uk Kim * PARAMETERS: Info - Method execution information block 444a159c266SJung-uk Kim * ReturnObject - Object returned from the evaluation of a 445a159c266SJung-uk Kim * method or object 446a159c266SJung-uk Kim * 447a159c266SJung-uk Kim * RETURN: Status 448a159c266SJung-uk Kim * 449a159c266SJung-uk Kim * DESCRIPTION: Check a returned reference object for the correct reference 450a159c266SJung-uk Kim * type. The only reference type that can be returned from a 451a159c266SJung-uk Kim * predefined method is a named reference. All others are invalid. 452a159c266SJung-uk Kim * 453a159c266SJung-uk Kim ******************************************************************************/ 454a159c266SJung-uk Kim 455a159c266SJung-uk Kim static ACPI_STATUS 456a159c266SJung-uk Kim AcpiNsCheckReference ( 457895f26a9SJung-uk Kim ACPI_EVALUATE_INFO *Info, 458a159c266SJung-uk Kim ACPI_OPERAND_OBJECT *ReturnObject) 459a159c266SJung-uk Kim { 460a159c266SJung-uk Kim 461a159c266SJung-uk Kim /* 462a159c266SJung-uk Kim * Check the reference object for the correct reference type (opcode). 463a159c266SJung-uk Kim * The only type of reference that can be converted to an ACPI_OBJECT is 464a159c266SJung-uk Kim * a reference to a named object (reference class: NAME) 465a159c266SJung-uk Kim */ 466a159c266SJung-uk Kim if (ReturnObject->Reference.Class == ACPI_REFCLASS_NAME) 467a159c266SJung-uk Kim { 468a159c266SJung-uk Kim return (AE_OK); 469a159c266SJung-uk Kim } 470a159c266SJung-uk Kim 471895f26a9SJung-uk Kim ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, 472a159c266SJung-uk Kim "Return type mismatch - unexpected reference object type [%s] %2.2X", 473a159c266SJung-uk Kim AcpiUtGetReferenceName (ReturnObject), 474a159c266SJung-uk Kim ReturnObject->Reference.Class)); 475a159c266SJung-uk Kim 476a159c266SJung-uk Kim return (AE_AML_OPERAND_TYPE); 477a159c266SJung-uk Kim } 478a159c266SJung-uk Kim 479a159c266SJung-uk Kim 480a159c266SJung-uk Kim /******************************************************************************* 481a159c266SJung-uk Kim * 4829c48c75eSJung-uk Kim * FUNCTION: AcpiNsGetBitmappedType 4839c48c75eSJung-uk Kim * 4849c48c75eSJung-uk Kim * PARAMETERS: ReturnObject - Object returned from method/obj evaluation 4859c48c75eSJung-uk Kim * 4869c48c75eSJung-uk Kim * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object 4879c48c75eSJung-uk Kim * type is not supported. ACPI_RTYPE_NONE indicates that no 4889c48c75eSJung-uk Kim * object was returned (ReturnObject is NULL). 4899c48c75eSJung-uk Kim * 4909c48c75eSJung-uk Kim * DESCRIPTION: Convert object type into a bitmapped object return type. 4919c48c75eSJung-uk Kim * 4929c48c75eSJung-uk Kim ******************************************************************************/ 4939c48c75eSJung-uk Kim 4949c48c75eSJung-uk Kim static UINT32 4959c48c75eSJung-uk Kim AcpiNsGetBitmappedType ( 4969c48c75eSJung-uk Kim ACPI_OPERAND_OBJECT *ReturnObject) 4979c48c75eSJung-uk Kim { 4989c48c75eSJung-uk Kim UINT32 ReturnBtype; 4999c48c75eSJung-uk Kim 5009c48c75eSJung-uk Kim 5019c48c75eSJung-uk Kim if (!ReturnObject) 5029c48c75eSJung-uk Kim { 5039c48c75eSJung-uk Kim return (ACPI_RTYPE_NONE); 5049c48c75eSJung-uk Kim } 5059c48c75eSJung-uk Kim 5069c48c75eSJung-uk Kim /* Map ACPI_OBJECT_TYPE to internal bitmapped type */ 5079c48c75eSJung-uk Kim 5089c48c75eSJung-uk Kim switch (ReturnObject->Common.Type) 5099c48c75eSJung-uk Kim { 5109c48c75eSJung-uk Kim case ACPI_TYPE_INTEGER: 511a9d8d09cSJung-uk Kim 5129c48c75eSJung-uk Kim ReturnBtype = ACPI_RTYPE_INTEGER; 5139c48c75eSJung-uk Kim break; 5149c48c75eSJung-uk Kim 5159c48c75eSJung-uk Kim case ACPI_TYPE_BUFFER: 516a9d8d09cSJung-uk Kim 5179c48c75eSJung-uk Kim ReturnBtype = ACPI_RTYPE_BUFFER; 5189c48c75eSJung-uk Kim break; 5199c48c75eSJung-uk Kim 5209c48c75eSJung-uk Kim case ACPI_TYPE_STRING: 521a9d8d09cSJung-uk Kim 5229c48c75eSJung-uk Kim ReturnBtype = ACPI_RTYPE_STRING; 5239c48c75eSJung-uk Kim break; 5249c48c75eSJung-uk Kim 5259c48c75eSJung-uk Kim case ACPI_TYPE_PACKAGE: 526a9d8d09cSJung-uk Kim 5279c48c75eSJung-uk Kim ReturnBtype = ACPI_RTYPE_PACKAGE; 5289c48c75eSJung-uk Kim break; 5299c48c75eSJung-uk Kim 5309c48c75eSJung-uk Kim case ACPI_TYPE_LOCAL_REFERENCE: 531a9d8d09cSJung-uk Kim 5329c48c75eSJung-uk Kim ReturnBtype = ACPI_RTYPE_REFERENCE; 5339c48c75eSJung-uk Kim break; 5349c48c75eSJung-uk Kim 5359c48c75eSJung-uk Kim default: 536a9d8d09cSJung-uk Kim 5379c48c75eSJung-uk Kim /* Not one of the supported objects, must be incorrect */ 5389c48c75eSJung-uk Kim 5399c48c75eSJung-uk Kim ReturnBtype = ACPI_RTYPE_ANY; 5409c48c75eSJung-uk Kim break; 5419c48c75eSJung-uk Kim } 5429c48c75eSJung-uk Kim 5439c48c75eSJung-uk Kim return (ReturnBtype); 5449c48c75eSJung-uk Kim } 545