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*f425b8beSJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2020, 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 226a159c266SJung-uk Kim 227a159c266SJung-uk Kim /* If not a predefined name, we cannot validate the return object */ 228a159c266SJung-uk Kim 229895f26a9SJung-uk Kim Predefined = Info->Predefined; 230a159c266SJung-uk Kim if (!Predefined) 231a159c266SJung-uk Kim { 232895f26a9SJung-uk Kim return (AE_OK); 233a159c266SJung-uk Kim } 234a159c266SJung-uk Kim 235a159c266SJung-uk Kim /* 236a159c266SJung-uk Kim * If the method failed or did not actually return an object, we cannot 237a159c266SJung-uk Kim * validate the return object 238a159c266SJung-uk Kim */ 239895f26a9SJung-uk Kim if ((ReturnStatus != AE_OK) && 240895f26a9SJung-uk Kim (ReturnStatus != AE_CTRL_RETURN_VALUE)) 241a159c266SJung-uk Kim { 242895f26a9SJung-uk Kim return (AE_OK); 243a159c266SJung-uk Kim } 244a159c266SJung-uk Kim 245a159c266SJung-uk Kim /* 246a159c266SJung-uk Kim * Return value validation and possible repair. 247a159c266SJung-uk Kim * 248a159c266SJung-uk Kim * 1) Don't perform return value validation/repair if this feature 249a159c266SJung-uk Kim * has been disabled via a global option. 250a159c266SJung-uk Kim * 251a159c266SJung-uk Kim * 2) We have a return value, but if one wasn't expected, just exit, 252a159c266SJung-uk Kim * this is not a problem. For example, if the "Implicit Return" 253a159c266SJung-uk Kim * feature is enabled, methods will always return a value. 254a159c266SJung-uk Kim * 255a159c266SJung-uk Kim * 3) If the return value can be of any type, then we cannot perform 256a159c266SJung-uk Kim * any validation, just exit. 257a159c266SJung-uk Kim */ 258a159c266SJung-uk Kim if (AcpiGbl_DisableAutoRepair || 259a159c266SJung-uk Kim (!Predefined->Info.ExpectedBtypes) || 260a159c266SJung-uk Kim (Predefined->Info.ExpectedBtypes == ACPI_RTYPE_ALL)) 261a159c266SJung-uk Kim { 262895f26a9SJung-uk Kim return (AE_OK); 263a159c266SJung-uk Kim } 264a159c266SJung-uk Kim 265a159c266SJung-uk Kim /* 266a159c266SJung-uk Kim * Check that the type of the main return object is what is expected 267a159c266SJung-uk Kim * for this predefined name 268a159c266SJung-uk Kim */ 269895f26a9SJung-uk Kim Status = AcpiNsCheckObjectType (Info, ReturnObjectPtr, 270a159c266SJung-uk Kim Predefined->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT); 271a159c266SJung-uk Kim if (ACPI_FAILURE (Status)) 272a159c266SJung-uk Kim { 273a159c266SJung-uk Kim goto Exit; 274a159c266SJung-uk Kim } 275a159c266SJung-uk Kim 276a159c266SJung-uk Kim /* 277bf6fac21SJung-uk Kim * 278bf6fac21SJung-uk Kim * 4) If there is no return value and it is optional, just return 279bf6fac21SJung-uk Kim * AE_OK (_WAK). 280bf6fac21SJung-uk Kim */ 281bf6fac21SJung-uk Kim if (!(*ReturnObjectPtr)) 282bf6fac21SJung-uk Kim { 283bf6fac21SJung-uk Kim goto Exit; 284bf6fac21SJung-uk Kim } 285bf6fac21SJung-uk Kim 286bf6fac21SJung-uk Kim /* 287a159c266SJung-uk Kim * For returned Package objects, check the type of all sub-objects. 288a159c266SJung-uk Kim * Note: Package may have been newly created by call above. 289a159c266SJung-uk Kim */ 290a159c266SJung-uk Kim if ((*ReturnObjectPtr)->Common.Type == ACPI_TYPE_PACKAGE) 291a159c266SJung-uk Kim { 292895f26a9SJung-uk Kim Info->ParentPackage = *ReturnObjectPtr; 293895f26a9SJung-uk Kim Status = AcpiNsCheckPackage (Info, ReturnObjectPtr); 294a159c266SJung-uk Kim if (ACPI_FAILURE (Status)) 295a159c266SJung-uk Kim { 296a9d8d09cSJung-uk Kim /* We might be able to fix some errors */ 297a9d8d09cSJung-uk Kim 298a9d8d09cSJung-uk Kim if ((Status != AE_AML_OPERAND_TYPE) && 299a9d8d09cSJung-uk Kim (Status != AE_AML_OPERAND_VALUE)) 300a9d8d09cSJung-uk Kim { 301a159c266SJung-uk Kim goto Exit; 302a159c266SJung-uk Kim } 303a159c266SJung-uk Kim } 304a9d8d09cSJung-uk Kim } 305a159c266SJung-uk Kim 306a159c266SJung-uk Kim /* 307a159c266SJung-uk Kim * The return object was OK, or it was successfully repaired above. 308a159c266SJung-uk Kim * Now make some additional checks such as verifying that package 309a159c266SJung-uk Kim * objects are sorted correctly (if required) or buffer objects have 310a159c266SJung-uk Kim * the correct data width (bytes vs. dwords). These repairs are 311a159c266SJung-uk Kim * performed on a per-name basis, i.e., the code is specific to 312a159c266SJung-uk Kim * particular predefined names. 313a159c266SJung-uk Kim */ 314895f26a9SJung-uk Kim Status = AcpiNsComplexRepairs (Info, Node, Status, ReturnObjectPtr); 315a159c266SJung-uk Kim 316a159c266SJung-uk Kim Exit: 317a159c266SJung-uk Kim /* 318a159c266SJung-uk Kim * If the object validation failed or if we successfully repaired one 319a159c266SJung-uk Kim * or more objects, mark the parent node to suppress further warning 320a159c266SJung-uk Kim * messages during the next evaluation of the same method/object. 321a159c266SJung-uk Kim */ 322895f26a9SJung-uk Kim if (ACPI_FAILURE (Status) || 323895f26a9SJung-uk Kim (Info->ReturnFlags & ACPI_OBJECT_REPAIRED)) 324a159c266SJung-uk Kim { 325a159c266SJung-uk Kim Node->Flags |= ANOBJ_EVALUATED; 326a159c266SJung-uk Kim } 327a159c266SJung-uk Kim 328a159c266SJung-uk Kim return (Status); 329a159c266SJung-uk Kim } 330a159c266SJung-uk Kim 331a159c266SJung-uk Kim 332a159c266SJung-uk Kim /******************************************************************************* 333a159c266SJung-uk Kim * 334a159c266SJung-uk Kim * FUNCTION: AcpiNsCheckObjectType 335a159c266SJung-uk Kim * 336895f26a9SJung-uk Kim * PARAMETERS: Info - Method execution information block 337a159c266SJung-uk Kim * ReturnObjectPtr - Pointer to the object returned from the 338a159c266SJung-uk Kim * evaluation of a method or object 339a159c266SJung-uk Kim * ExpectedBtypes - Bitmap of expected return type(s) 340a159c266SJung-uk Kim * PackageIndex - Index of object within parent package (if 341a159c266SJung-uk Kim * applicable - ACPI_NOT_PACKAGE_ELEMENT 342a159c266SJung-uk Kim * otherwise) 343a159c266SJung-uk Kim * 344a159c266SJung-uk Kim * RETURN: Status 345a159c266SJung-uk Kim * 346a159c266SJung-uk Kim * DESCRIPTION: Check the type of the return object against the expected object 347a159c266SJung-uk Kim * type(s). Use of Btype allows multiple expected object types. 348a159c266SJung-uk Kim * 349a159c266SJung-uk Kim ******************************************************************************/ 350a159c266SJung-uk Kim 351efcc2a30SJung-uk Kim ACPI_STATUS 352a159c266SJung-uk Kim AcpiNsCheckObjectType ( 353895f26a9SJung-uk Kim ACPI_EVALUATE_INFO *Info, 354a159c266SJung-uk Kim ACPI_OPERAND_OBJECT **ReturnObjectPtr, 355a159c266SJung-uk Kim UINT32 ExpectedBtypes, 356a159c266SJung-uk Kim UINT32 PackageIndex) 357a159c266SJung-uk Kim { 358a159c266SJung-uk Kim ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr; 359a159c266SJung-uk Kim ACPI_STATUS Status = AE_OK; 360f8146b88SJung-uk Kim char TypeBuffer[96]; /* Room for 10 types */ 361a159c266SJung-uk Kim 362a159c266SJung-uk Kim 363a159c266SJung-uk Kim /* A Namespace node should not get here, but make sure */ 364a159c266SJung-uk Kim 3659c48c75eSJung-uk Kim if (ReturnObject && 3669c48c75eSJung-uk Kim ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED) 367a159c266SJung-uk Kim { 368895f26a9SJung-uk Kim ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, 369a159c266SJung-uk Kim "Invalid return type - Found a Namespace node [%4.4s] type %s", 370a159c266SJung-uk Kim ReturnObject->Node.Name.Ascii, 371a159c266SJung-uk Kim AcpiUtGetTypeName (ReturnObject->Node.Type))); 372a159c266SJung-uk Kim return (AE_AML_OPERAND_TYPE); 373a159c266SJung-uk Kim } 374a159c266SJung-uk Kim 375a159c266SJung-uk Kim /* 376a159c266SJung-uk Kim * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type. 377a159c266SJung-uk Kim * The bitmapped type allows multiple possible return types. 378a159c266SJung-uk Kim * 379a159c266SJung-uk Kim * Note, the cases below must handle all of the possible types returned 380a159c266SJung-uk Kim * from all of the predefined names (including elements of returned 381a159c266SJung-uk Kim * packages) 382a159c266SJung-uk Kim */ 383895f26a9SJung-uk Kim Info->ReturnBtype = AcpiNsGetBitmappedType (ReturnObject); 384895f26a9SJung-uk Kim if (Info->ReturnBtype == ACPI_RTYPE_ANY) 385a159c266SJung-uk Kim { 386a159c266SJung-uk Kim /* Not one of the supported objects, must be incorrect */ 387a159c266SJung-uk Kim goto TypeErrorExit; 388a159c266SJung-uk Kim } 389a159c266SJung-uk Kim 390a159c266SJung-uk Kim /* For reference objects, check that the reference type is correct */ 391a159c266SJung-uk Kim 392895f26a9SJung-uk Kim if ((Info->ReturnBtype & ExpectedBtypes) == ACPI_RTYPE_REFERENCE) 393a159c266SJung-uk Kim { 394895f26a9SJung-uk Kim Status = AcpiNsCheckReference (Info, ReturnObject); 395a159c266SJung-uk Kim return (Status); 396a159c266SJung-uk Kim } 397a159c266SJung-uk Kim 3989c48c75eSJung-uk Kim /* Attempt simple repair of the returned object if necessary */ 399a159c266SJung-uk Kim 400895f26a9SJung-uk Kim Status = AcpiNsSimpleRepair (Info, ExpectedBtypes, 401a159c266SJung-uk Kim PackageIndex, ReturnObjectPtr); 402895f26a9SJung-uk Kim if (ACPI_SUCCESS (Status)) 403895f26a9SJung-uk Kim { 404895f26a9SJung-uk Kim return (AE_OK); /* Successful repair */ 405895f26a9SJung-uk Kim } 406a159c266SJung-uk Kim 407a159c266SJung-uk Kim 408a159c266SJung-uk Kim TypeErrorExit: 409a159c266SJung-uk Kim 410a159c266SJung-uk Kim /* Create a string with all expected types for this predefined object */ 411a159c266SJung-uk Kim 4129c7c683cSJung-uk Kim AcpiUtGetExpectedReturnTypes (TypeBuffer, ExpectedBtypes); 413a159c266SJung-uk Kim 414bf6fac21SJung-uk Kim if (!ReturnObject) 415bf6fac21SJung-uk Kim { 416bf6fac21SJung-uk Kim ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, 417bf6fac21SJung-uk Kim "Expected return object of type %s", 418bf6fac21SJung-uk Kim TypeBuffer)); 419bf6fac21SJung-uk Kim } 420bf6fac21SJung-uk Kim else if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT) 421a159c266SJung-uk Kim { 422895f26a9SJung-uk Kim ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, 423a159c266SJung-uk Kim "Return type mismatch - found %s, expected %s", 424a159c266SJung-uk Kim AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer)); 425a159c266SJung-uk Kim } 426a159c266SJung-uk Kim else 427a159c266SJung-uk Kim { 428895f26a9SJung-uk Kim ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, 429a159c266SJung-uk Kim "Return Package type mismatch at index %u - " 430a159c266SJung-uk Kim "found %s, expected %s", PackageIndex, 431a159c266SJung-uk Kim AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer)); 432a159c266SJung-uk Kim } 433a159c266SJung-uk Kim 434a159c266SJung-uk Kim return (AE_AML_OPERAND_TYPE); 435a159c266SJung-uk Kim } 436a159c266SJung-uk Kim 437a159c266SJung-uk Kim 438a159c266SJung-uk Kim /******************************************************************************* 439a159c266SJung-uk Kim * 440a159c266SJung-uk Kim * FUNCTION: AcpiNsCheckReference 441a159c266SJung-uk Kim * 442895f26a9SJung-uk Kim * PARAMETERS: Info - Method execution information block 443a159c266SJung-uk Kim * ReturnObject - Object returned from the evaluation of a 444a159c266SJung-uk Kim * method or object 445a159c266SJung-uk Kim * 446a159c266SJung-uk Kim * RETURN: Status 447a159c266SJung-uk Kim * 448a159c266SJung-uk Kim * DESCRIPTION: Check a returned reference object for the correct reference 449a159c266SJung-uk Kim * type. The only reference type that can be returned from a 450a159c266SJung-uk Kim * predefined method is a named reference. All others are invalid. 451a159c266SJung-uk Kim * 452a159c266SJung-uk Kim ******************************************************************************/ 453a159c266SJung-uk Kim 454a159c266SJung-uk Kim static ACPI_STATUS 455a159c266SJung-uk Kim AcpiNsCheckReference ( 456895f26a9SJung-uk Kim ACPI_EVALUATE_INFO *Info, 457a159c266SJung-uk Kim ACPI_OPERAND_OBJECT *ReturnObject) 458a159c266SJung-uk Kim { 459a159c266SJung-uk Kim 460a159c266SJung-uk Kim /* 461a159c266SJung-uk Kim * Check the reference object for the correct reference type (opcode). 462a159c266SJung-uk Kim * The only type of reference that can be converted to an ACPI_OBJECT is 463a159c266SJung-uk Kim * a reference to a named object (reference class: NAME) 464a159c266SJung-uk Kim */ 465a159c266SJung-uk Kim if (ReturnObject->Reference.Class == ACPI_REFCLASS_NAME) 466a159c266SJung-uk Kim { 467a159c266SJung-uk Kim return (AE_OK); 468a159c266SJung-uk Kim } 469a159c266SJung-uk Kim 470895f26a9SJung-uk Kim ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, 471a159c266SJung-uk Kim "Return type mismatch - unexpected reference object type [%s] %2.2X", 472a159c266SJung-uk Kim AcpiUtGetReferenceName (ReturnObject), 473a159c266SJung-uk Kim ReturnObject->Reference.Class)); 474a159c266SJung-uk Kim 475a159c266SJung-uk Kim return (AE_AML_OPERAND_TYPE); 476a159c266SJung-uk Kim } 477a159c266SJung-uk Kim 478a159c266SJung-uk Kim 479a159c266SJung-uk Kim /******************************************************************************* 480a159c266SJung-uk Kim * 4819c48c75eSJung-uk Kim * FUNCTION: AcpiNsGetBitmappedType 4829c48c75eSJung-uk Kim * 4839c48c75eSJung-uk Kim * PARAMETERS: ReturnObject - Object returned from method/obj evaluation 4849c48c75eSJung-uk Kim * 4859c48c75eSJung-uk Kim * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object 4869c48c75eSJung-uk Kim * type is not supported. ACPI_RTYPE_NONE indicates that no 4879c48c75eSJung-uk Kim * object was returned (ReturnObject is NULL). 4889c48c75eSJung-uk Kim * 4899c48c75eSJung-uk Kim * DESCRIPTION: Convert object type into a bitmapped object return type. 4909c48c75eSJung-uk Kim * 4919c48c75eSJung-uk Kim ******************************************************************************/ 4929c48c75eSJung-uk Kim 4939c48c75eSJung-uk Kim static UINT32 4949c48c75eSJung-uk Kim AcpiNsGetBitmappedType ( 4959c48c75eSJung-uk Kim ACPI_OPERAND_OBJECT *ReturnObject) 4969c48c75eSJung-uk Kim { 4979c48c75eSJung-uk Kim UINT32 ReturnBtype; 4989c48c75eSJung-uk Kim 4999c48c75eSJung-uk Kim 5009c48c75eSJung-uk Kim if (!ReturnObject) 5019c48c75eSJung-uk Kim { 5029c48c75eSJung-uk Kim return (ACPI_RTYPE_NONE); 5039c48c75eSJung-uk Kim } 5049c48c75eSJung-uk Kim 5059c48c75eSJung-uk Kim /* Map ACPI_OBJECT_TYPE to internal bitmapped type */ 5069c48c75eSJung-uk Kim 5079c48c75eSJung-uk Kim switch (ReturnObject->Common.Type) 5089c48c75eSJung-uk Kim { 5099c48c75eSJung-uk Kim case ACPI_TYPE_INTEGER: 510a9d8d09cSJung-uk Kim 5119c48c75eSJung-uk Kim ReturnBtype = ACPI_RTYPE_INTEGER; 5129c48c75eSJung-uk Kim break; 5139c48c75eSJung-uk Kim 5149c48c75eSJung-uk Kim case ACPI_TYPE_BUFFER: 515a9d8d09cSJung-uk Kim 5169c48c75eSJung-uk Kim ReturnBtype = ACPI_RTYPE_BUFFER; 5179c48c75eSJung-uk Kim break; 5189c48c75eSJung-uk Kim 5199c48c75eSJung-uk Kim case ACPI_TYPE_STRING: 520a9d8d09cSJung-uk Kim 5219c48c75eSJung-uk Kim ReturnBtype = ACPI_RTYPE_STRING; 5229c48c75eSJung-uk Kim break; 5239c48c75eSJung-uk Kim 5249c48c75eSJung-uk Kim case ACPI_TYPE_PACKAGE: 525a9d8d09cSJung-uk Kim 5269c48c75eSJung-uk Kim ReturnBtype = ACPI_RTYPE_PACKAGE; 5279c48c75eSJung-uk Kim break; 5289c48c75eSJung-uk Kim 5299c48c75eSJung-uk Kim case ACPI_TYPE_LOCAL_REFERENCE: 530a9d8d09cSJung-uk Kim 5319c48c75eSJung-uk Kim ReturnBtype = ACPI_RTYPE_REFERENCE; 5329c48c75eSJung-uk Kim break; 5339c48c75eSJung-uk Kim 5349c48c75eSJung-uk Kim default: 535a9d8d09cSJung-uk Kim 5369c48c75eSJung-uk Kim /* Not one of the supported objects, must be incorrect */ 5379c48c75eSJung-uk Kim 5389c48c75eSJung-uk Kim ReturnBtype = ACPI_RTYPE_ANY; 5399c48c75eSJung-uk Kim break; 5409c48c75eSJung-uk Kim } 5419c48c75eSJung-uk Kim 5429c48c75eSJung-uk Kim return (ReturnBtype); 5439c48c75eSJung-uk Kim } 544