1 /****************************************************************************** 2 * 3 * Module Name: nspredef - Validation of ACPI predefined methods and objects 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2013, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44 #define ACPI_CREATE_PREDEFINED_TABLE 45 46 #include <contrib/dev/acpica/include/acpi.h> 47 #include <contrib/dev/acpica/include/accommon.h> 48 #include <contrib/dev/acpica/include/acnamesp.h> 49 #include <contrib/dev/acpica/include/acpredef.h> 50 51 52 #define _COMPONENT ACPI_NAMESPACE 53 ACPI_MODULE_NAME ("nspredef") 54 55 56 /******************************************************************************* 57 * 58 * This module validates predefined ACPI objects that appear in the namespace, 59 * at the time they are evaluated (via AcpiEvaluateObject). The purpose of this 60 * validation is to detect problems with BIOS-exposed predefined ACPI objects 61 * before the results are returned to the ACPI-related drivers. 62 * 63 * There are several areas that are validated: 64 * 65 * 1) The number of input arguments as defined by the method/object in the 66 * ASL is validated against the ACPI specification. 67 * 2) The type of the return object (if any) is validated against the ACPI 68 * specification. 69 * 3) For returned package objects, the count of package elements is 70 * validated, as well as the type of each package element. Nested 71 * packages are supported. 72 * 73 * For any problems found, a warning message is issued. 74 * 75 ******************************************************************************/ 76 77 78 /* Local prototypes */ 79 80 static ACPI_STATUS 81 AcpiNsCheckReference ( 82 ACPI_PREDEFINED_DATA *Data, 83 ACPI_OPERAND_OBJECT *ReturnObject); 84 85 static UINT32 86 AcpiNsGetBitmappedType ( 87 ACPI_OPERAND_OBJECT *ReturnObject); 88 89 90 /******************************************************************************* 91 * 92 * FUNCTION: AcpiNsCheckPredefinedNames 93 * 94 * PARAMETERS: Node - Namespace node for the method/object 95 * UserParamCount - Number of parameters actually passed 96 * ReturnStatus - Status from the object evaluation 97 * ReturnObjectPtr - Pointer to the object returned from the 98 * evaluation of a method or object 99 * 100 * RETURN: Status 101 * 102 * DESCRIPTION: Check an ACPI name for a match in the predefined name list. 103 * 104 ******************************************************************************/ 105 106 ACPI_STATUS 107 AcpiNsCheckPredefinedNames ( 108 ACPI_NAMESPACE_NODE *Node, 109 UINT32 UserParamCount, 110 ACPI_STATUS ReturnStatus, 111 ACPI_OPERAND_OBJECT **ReturnObjectPtr) 112 { 113 ACPI_STATUS Status = AE_OK; 114 const ACPI_PREDEFINED_INFO *Predefined; 115 char *Pathname; 116 ACPI_PREDEFINED_DATA *Data; 117 118 119 /* Match the name for this method/object against the predefined list */ 120 121 Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii); 122 123 /* Get the full pathname to the object, for use in warning messages */ 124 125 Pathname = AcpiNsGetExternalPathname (Node); 126 if (!Pathname) 127 { 128 return (AE_OK); /* Could not get pathname, ignore */ 129 } 130 131 /* 132 * Check that the parameter count for this method matches the ASL 133 * definition. For predefined names, ensure that both the caller and 134 * the method itself are in accordance with the ACPI specification. 135 */ 136 AcpiNsCheckParameterCount (Pathname, Node, UserParamCount, Predefined); 137 138 /* If not a predefined name, we cannot validate the return object */ 139 140 if (!Predefined) 141 { 142 goto Cleanup; 143 } 144 145 /* 146 * If the method failed or did not actually return an object, we cannot 147 * validate the return object 148 */ 149 if ((ReturnStatus != AE_OK) && (ReturnStatus != AE_CTRL_RETURN_VALUE)) 150 { 151 goto Cleanup; 152 } 153 154 /* 155 * Return value validation and possible repair. 156 * 157 * 1) Don't perform return value validation/repair if this feature 158 * has been disabled via a global option. 159 * 160 * 2) We have a return value, but if one wasn't expected, just exit, 161 * this is not a problem. For example, if the "Implicit Return" 162 * feature is enabled, methods will always return a value. 163 * 164 * 3) If the return value can be of any type, then we cannot perform 165 * any validation, just exit. 166 */ 167 if (AcpiGbl_DisableAutoRepair || 168 (!Predefined->Info.ExpectedBtypes) || 169 (Predefined->Info.ExpectedBtypes == ACPI_RTYPE_ALL)) 170 { 171 goto Cleanup; 172 } 173 174 /* Create the parameter data block for object validation */ 175 176 Data = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PREDEFINED_DATA)); 177 if (!Data) 178 { 179 goto Cleanup; 180 } 181 Data->Predefined = Predefined; 182 Data->Node = Node; 183 Data->NodeFlags = Node->Flags; 184 Data->Pathname = Pathname; 185 186 /* 187 * Check that the type of the main return object is what is expected 188 * for this predefined name 189 */ 190 Status = AcpiNsCheckObjectType (Data, ReturnObjectPtr, 191 Predefined->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT); 192 if (ACPI_FAILURE (Status)) 193 { 194 goto Exit; 195 } 196 197 /* 198 * For returned Package objects, check the type of all sub-objects. 199 * Note: Package may have been newly created by call above. 200 */ 201 if ((*ReturnObjectPtr)->Common.Type == ACPI_TYPE_PACKAGE) 202 { 203 Data->ParentPackage = *ReturnObjectPtr; 204 Status = AcpiNsCheckPackage (Data, ReturnObjectPtr); 205 if (ACPI_FAILURE (Status)) 206 { 207 goto Exit; 208 } 209 } 210 211 /* 212 * The return object was OK, or it was successfully repaired above. 213 * Now make some additional checks such as verifying that package 214 * objects are sorted correctly (if required) or buffer objects have 215 * the correct data width (bytes vs. dwords). These repairs are 216 * performed on a per-name basis, i.e., the code is specific to 217 * particular predefined names. 218 */ 219 Status = AcpiNsComplexRepairs (Data, Node, Status, ReturnObjectPtr); 220 221 Exit: 222 /* 223 * If the object validation failed or if we successfully repaired one 224 * or more objects, mark the parent node to suppress further warning 225 * messages during the next evaluation of the same method/object. 226 */ 227 if (ACPI_FAILURE (Status) || (Data->Flags & ACPI_OBJECT_REPAIRED)) 228 { 229 Node->Flags |= ANOBJ_EVALUATED; 230 } 231 ACPI_FREE (Data); 232 233 Cleanup: 234 ACPI_FREE (Pathname); 235 return (Status); 236 } 237 238 239 /******************************************************************************* 240 * 241 * FUNCTION: AcpiNsCheckParameterCount 242 * 243 * PARAMETERS: Pathname - Full pathname to the node (for error msgs) 244 * Node - Namespace node for the method/object 245 * UserParamCount - Number of args passed in by the caller 246 * Predefined - Pointer to entry in predefined name table 247 * 248 * RETURN: None 249 * 250 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a 251 * predefined name is what is expected (i.e., what is defined in 252 * the ACPI specification for this predefined name.) 253 * 254 ******************************************************************************/ 255 256 void 257 AcpiNsCheckParameterCount ( 258 char *Pathname, 259 ACPI_NAMESPACE_NODE *Node, 260 UINT32 UserParamCount, 261 const ACPI_PREDEFINED_INFO *Predefined) 262 { 263 UINT32 ParamCount; 264 UINT32 RequiredParamsCurrent; 265 UINT32 RequiredParamsOld; 266 267 268 /* Methods have 0-7 parameters. All other types have zero. */ 269 270 ParamCount = 0; 271 if (Node->Type == ACPI_TYPE_METHOD) 272 { 273 ParamCount = Node->Object->Method.ParamCount; 274 } 275 276 if (!Predefined) 277 { 278 /* 279 * Check the parameter count for non-predefined methods/objects. 280 * 281 * Warning if too few or too many arguments have been passed by the 282 * caller. An incorrect number of arguments may not cause the method 283 * to fail. However, the method will fail if there are too few 284 * arguments and the method attempts to use one of the missing ones. 285 */ 286 if (UserParamCount < ParamCount) 287 { 288 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS, 289 "Insufficient arguments - needs %u, found %u", 290 ParamCount, UserParamCount)); 291 } 292 else if (UserParamCount > ParamCount) 293 { 294 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS, 295 "Excess arguments - needs %u, found %u", 296 ParamCount, UserParamCount)); 297 } 298 return; 299 } 300 301 /* 302 * Validate the user-supplied parameter count. 303 * Allow two different legal argument counts (_SCP, etc.) 304 */ 305 RequiredParamsCurrent = Predefined->Info.ArgumentList & METHOD_ARG_MASK; 306 RequiredParamsOld = Predefined->Info.ArgumentList >> METHOD_ARG_BIT_WIDTH; 307 308 if (UserParamCount != ACPI_UINT32_MAX) 309 { 310 if ((UserParamCount != RequiredParamsCurrent) && 311 (UserParamCount != RequiredParamsOld)) 312 { 313 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS, 314 "Parameter count mismatch - " 315 "caller passed %u, ACPI requires %u", 316 UserParamCount, RequiredParamsCurrent)); 317 } 318 } 319 320 /* 321 * Check that the ASL-defined parameter count is what is expected for 322 * this predefined name (parameter count as defined by the ACPI 323 * specification) 324 */ 325 if ((ParamCount != RequiredParamsCurrent) && 326 (ParamCount != RequiredParamsOld)) 327 { 328 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, Node->Flags, 329 "Parameter count mismatch - ASL declared %u, ACPI requires %u", 330 ParamCount, RequiredParamsCurrent)); 331 } 332 } 333 334 335 /******************************************************************************* 336 * 337 * FUNCTION: AcpiNsCheckObjectType 338 * 339 * PARAMETERS: Data - Pointer to validation data structure 340 * ReturnObjectPtr - Pointer to the object returned from the 341 * evaluation of a method or object 342 * ExpectedBtypes - Bitmap of expected return type(s) 343 * PackageIndex - Index of object within parent package (if 344 * applicable - ACPI_NOT_PACKAGE_ELEMENT 345 * otherwise) 346 * 347 * RETURN: Status 348 * 349 * DESCRIPTION: Check the type of the return object against the expected object 350 * type(s). Use of Btype allows multiple expected object types. 351 * 352 ******************************************************************************/ 353 354 ACPI_STATUS 355 AcpiNsCheckObjectType ( 356 ACPI_PREDEFINED_DATA *Data, 357 ACPI_OPERAND_OBJECT **ReturnObjectPtr, 358 UINT32 ExpectedBtypes, 359 UINT32 PackageIndex) 360 { 361 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr; 362 ACPI_STATUS Status = AE_OK; 363 char TypeBuffer[48]; /* Room for 5 types */ 364 365 366 /* A Namespace node should not get here, but make sure */ 367 368 if (ReturnObject && 369 ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED) 370 { 371 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags, 372 "Invalid return type - Found a Namespace node [%4.4s] type %s", 373 ReturnObject->Node.Name.Ascii, 374 AcpiUtGetTypeName (ReturnObject->Node.Type))); 375 return (AE_AML_OPERAND_TYPE); 376 } 377 378 /* 379 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type. 380 * The bitmapped type allows multiple possible return types. 381 * 382 * Note, the cases below must handle all of the possible types returned 383 * from all of the predefined names (including elements of returned 384 * packages) 385 */ 386 Data->ReturnBtype = AcpiNsGetBitmappedType (ReturnObject); 387 if (Data->ReturnBtype == ACPI_RTYPE_ANY) 388 { 389 /* Not one of the supported objects, must be incorrect */ 390 goto TypeErrorExit; 391 } 392 393 /* For reference objects, check that the reference type is correct */ 394 395 if ((Data->ReturnBtype & ExpectedBtypes) == ACPI_RTYPE_REFERENCE) 396 { 397 Status = AcpiNsCheckReference (Data, ReturnObject); 398 return (Status); 399 } 400 401 /* Attempt simple repair of the returned object if necessary */ 402 403 Status = AcpiNsSimpleRepair (Data, ExpectedBtypes, 404 PackageIndex, ReturnObjectPtr); 405 return (Status); 406 407 408 TypeErrorExit: 409 410 /* Create a string with all expected types for this predefined object */ 411 412 AcpiUtGetExpectedReturnTypes (TypeBuffer, ExpectedBtypes); 413 414 if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT) 415 { 416 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags, 417 "Return type mismatch - found %s, expected %s", 418 AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer)); 419 } 420 else 421 { 422 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags, 423 "Return Package type mismatch at index %u - " 424 "found %s, expected %s", PackageIndex, 425 AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer)); 426 } 427 428 return (AE_AML_OPERAND_TYPE); 429 } 430 431 432 /******************************************************************************* 433 * 434 * FUNCTION: AcpiNsCheckReference 435 * 436 * PARAMETERS: Data - Pointer to validation data structure 437 * ReturnObject - Object returned from the evaluation of a 438 * method or object 439 * 440 * RETURN: Status 441 * 442 * DESCRIPTION: Check a returned reference object for the correct reference 443 * type. The only reference type that can be returned from a 444 * predefined method is a named reference. All others are invalid. 445 * 446 ******************************************************************************/ 447 448 static ACPI_STATUS 449 AcpiNsCheckReference ( 450 ACPI_PREDEFINED_DATA *Data, 451 ACPI_OPERAND_OBJECT *ReturnObject) 452 { 453 454 /* 455 * Check the reference object for the correct reference type (opcode). 456 * The only type of reference that can be converted to an ACPI_OBJECT is 457 * a reference to a named object (reference class: NAME) 458 */ 459 if (ReturnObject->Reference.Class == ACPI_REFCLASS_NAME) 460 { 461 return (AE_OK); 462 } 463 464 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags, 465 "Return type mismatch - unexpected reference object type [%s] %2.2X", 466 AcpiUtGetReferenceName (ReturnObject), 467 ReturnObject->Reference.Class)); 468 469 return (AE_AML_OPERAND_TYPE); 470 } 471 472 473 /******************************************************************************* 474 * 475 * FUNCTION: AcpiNsGetBitmappedType 476 * 477 * PARAMETERS: ReturnObject - Object returned from method/obj evaluation 478 * 479 * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object 480 * type is not supported. ACPI_RTYPE_NONE indicates that no 481 * object was returned (ReturnObject is NULL). 482 * 483 * DESCRIPTION: Convert object type into a bitmapped object return type. 484 * 485 ******************************************************************************/ 486 487 static UINT32 488 AcpiNsGetBitmappedType ( 489 ACPI_OPERAND_OBJECT *ReturnObject) 490 { 491 UINT32 ReturnBtype; 492 493 494 if (!ReturnObject) 495 { 496 return (ACPI_RTYPE_NONE); 497 } 498 499 /* Map ACPI_OBJECT_TYPE to internal bitmapped type */ 500 501 switch (ReturnObject->Common.Type) 502 { 503 case ACPI_TYPE_INTEGER: 504 ReturnBtype = ACPI_RTYPE_INTEGER; 505 break; 506 507 case ACPI_TYPE_BUFFER: 508 ReturnBtype = ACPI_RTYPE_BUFFER; 509 break; 510 511 case ACPI_TYPE_STRING: 512 ReturnBtype = ACPI_RTYPE_STRING; 513 break; 514 515 case ACPI_TYPE_PACKAGE: 516 ReturnBtype = ACPI_RTYPE_PACKAGE; 517 break; 518 519 case ACPI_TYPE_LOCAL_REFERENCE: 520 ReturnBtype = ACPI_RTYPE_REFERENCE; 521 break; 522 523 default: 524 /* Not one of the supported objects, must be incorrect */ 525 526 ReturnBtype = ACPI_RTYPE_ANY; 527 break; 528 } 529 530 return (ReturnBtype); 531 } 532