nspredef.c revision 7b1019a6d29ccb7999dc76cba3dde1c627e8e609
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers/******************************************************************************
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * Module Name: nspredef - Validation of ACPI predefined methods and objects
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers *****************************************************************************/
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * All rights reserved.
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * Redistribution and use in source and binary forms, with or without
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * modification, are permitted provided that the following conditions
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * 1. Redistributions of source code must retain the above copyright
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * notice, this list of conditions, and the following disclaimer,
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * without modification.
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * including a substantially similar Disclaimer requirement for further
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * binary redistribution.
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * of any contributors may be used to endorse or promote products derived
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * from this software without specific prior written permission.
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * Alternatively, this software may be distributed under the terms of the
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * GNU General Public License ("GPL") version 2 as published by the Free
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * Software Foundation.
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * NO WARRANTY
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * POSSIBILITY OF SUCH DAMAGES.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers/*******************************************************************************
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * This module validates predefined ACPI objects that appear in the namespace,
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * at the time they are evaluated (via AcpiEvaluateObject). The purpose of this
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * validation is to detect problems with BIOS-exposed predefined ACPI objects
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * before the results are returned to the ACPI-related drivers.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * There are several areas that are validated:
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * 1) The number of input arguments as defined by the method/object in the
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * ASL is validated against the ACPI specification.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * 2) The type of the return object (if any) is validated against the ACPI
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * specification.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * 3) For returned package objects, the count of package elements is
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * validated, as well as the type of each package element. Nested
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * packages are supported.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * For any problems found, a warning message is issued.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers ******************************************************************************/
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers/* Local prototypes */
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers/*******************************************************************************
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * FUNCTION: AcpiNsCheckReturnValue
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * PARAMETERS: Node - Namespace node for the method/object
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * Info - Method execution information block
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers * UserParamCount - Number of parameters actually passed
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers * ReturnStatus - Status from the object evaluation
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * ReturnObjectPtr - Pointer to the object returned from the
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * evaluation of a method or object
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * RETURN: Status
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * DESCRIPTION: Check the value returned from a predefined name.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers ******************************************************************************/
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers /* If not a predefined name, we cannot validate the return object */
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers * If the method failed or did not actually return an object, we cannot
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers * validate the return object
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * Return value validation and possible repair.
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * 1) Don't perform return value validation/repair if this feature
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * has been disabled via a global option.
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * 2) We have a return value, but if one wasn't expected, just exit,
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * this is not a problem. For example, if the "Implicit Return"
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * feature is enabled, methods will always return a value.
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * 3) If the return value can be of any type, then we cannot perform
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * any validation, just exit.
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers (Predefined->Info.ExpectedBtypes == ACPI_RTYPE_ALL))
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * Check that the type of the main return object is what is expected
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * for this predefined name
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek Status = AcpiNsCheckObjectType (Info, ReturnObjectPtr,
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek Predefined->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * 4) If there is no return value and it is optional, just return
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * AE_OK (_WAK).
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * For returned Package objects, check the type of all sub-objects.
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * Note: Package may have been newly created by call above.
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross if ((*ReturnObjectPtr)->Common.Type == ACPI_TYPE_PACKAGE)
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek Status = AcpiNsCheckPackage (Info, ReturnObjectPtr);
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek /* We might be able to fix some errors */
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * The return object was OK, or it was successfully repaired above.
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * Now make some additional checks such as verifying that package
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * objects are sorted correctly (if required) or buffer objects have
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * the correct data width (bytes vs. dwords). These repairs are
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * performed on a per-name basis, i.e., the code is specific to
26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0Gordon Ross * particular predefined names.
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek Status = AcpiNsComplexRepairs (Info, Node, Status, ReturnObjectPtr);
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers * If the object validation failed or if we successfully repaired one
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers * or more objects, mark the parent node to suppress further warning
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers * messages during the next evaluation of the same method/object.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers/*******************************************************************************
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * FUNCTION: AcpiNsCheckObjectType
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * PARAMETERS: Info - Method execution information block
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * ReturnObjectPtr - Pointer to the object returned from the
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * evaluation of a method or object
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * ExpectedBtypes - Bitmap of expected return type(s)
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * PackageIndex - Index of object within parent package (if
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers * applicable - ACPI_NOT_PACKAGE_ELEMENT
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers * otherwise)
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * RETURN: Status
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * DESCRIPTION: Check the type of the return object against the expected object
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * type(s). Use of Btype allows multiple expected object types.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers ******************************************************************************/
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers /* A Namespace node should not get here, but make sure */
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED)
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers "Invalid return type - Found a Namespace node [%4.4s] type %s",
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * The bitmapped type allows multiple possible return types.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * Note, the cases below must handle all of the possible types returned
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * from all of the predefined names (including elements of returned
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek Info->ReturnBtype = AcpiNsGetBitmappedType (ReturnObject);
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers /* Not one of the supported objects, must be incorrect */
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek /* For reference objects, check that the reference type is correct */
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek if ((Info->ReturnBtype & ExpectedBtypes) == ACPI_RTYPE_REFERENCE)
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek Status = AcpiNsCheckReference (Info, ReturnObject);
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek /* Attempt simple repair of the returned object if necessary */
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek Status = AcpiNsSimpleRepair (Info, ExpectedBtypes,
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers /* Create a string with all expected types for this predefined object */
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek AcpiUtGetExpectedReturnTypes (TypeBuffer, ExpectedBtypes);
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek "Expected return object of type %s",
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek else if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT)
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers "Return type mismatch - found %s, expected %s",
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers "Return Package type mismatch at index %u - "
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers/*******************************************************************************
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * FUNCTION: AcpiNsCheckReference
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * PARAMETERS: Info - Method execution information block
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * ReturnObject - Object returned from the evaluation of a
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * method or object
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * RETURN: Status
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * DESCRIPTION: Check a returned reference object for the correct reference
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * type. The only reference type that can be returned from a
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * predefined method is a named reference. All others are invalid.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers ******************************************************************************/
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * Check the reference object for the correct reference type (opcode).
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * The only type of reference that can be converted to an ACPI_OBJECT is
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers * a reference to a named object (reference class: NAME)
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers if (ReturnObject->Reference.Class == ACPI_REFCLASS_NAME)
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers "Return type mismatch - unexpected reference object type [%s] %2.2X",
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers/*******************************************************************************
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * FUNCTION: AcpiNsGetBitmappedType
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * PARAMETERS: ReturnObject - Object returned from method/obj evaluation
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * type is not supported. ACPI_RTYPE_NONE indicates that no
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * object was returned (ReturnObject is NULL).
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek * DESCRIPTION: Convert object type into a bitmapped object return type.
aa2aa9a662539940ddbc8610da5a3a874ebd7503Dana Myers ******************************************************************************/
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek /* Map ACPI_OBJECT_TYPE to internal bitmapped type */
7b1019a6d29ccb7999dc76cba3dde1c627e8e609Jerry Jelinek /* Not one of the supported objects, must be incorrect */