nspredef.c revision 999e08f99846a1fd6ee9642ec306a2d318925116
1/****************************************************************************** 2 * 3 * Module Name: nspredef - Validation of ACPI predefined methods and objects 4 * $Revision: 1.1 $ 5 * 6 *****************************************************************************/ 7 8/* 9 * Copyright (C) 2000 - 2008, Intel Corp. 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions, and the following disclaimer, 17 * without modification. 18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 19 * substantially similar to the "NO WARRANTY" disclaimer below 20 * ("Disclaimer") and any redistribution must be conditioned upon 21 * including a substantially similar Disclaimer requirement for further 22 * binary redistribution. 23 * 3. Neither the names of the above-listed copyright holders nor the names 24 * of any contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * Alternatively, this software may be distributed under the terms of the 28 * GNU General Public License ("GPL") version 2 as published by the Free 29 * Software Foundation. 30 * 31 * NO WARRANTY 32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42 * POSSIBILITY OF SUCH DAMAGES. 43 */ 44 45#define ACPI_CREATE_PREDEFINED_TABLE 46 47#include <acpi/acpi.h> 48#include "accommon.h" 49#include "acnamesp.h" 50#include "acpredef.h" 51 52#define _COMPONENT ACPI_NAMESPACE 53ACPI_MODULE_NAME("nspredef") 54 55/******************************************************************************* 56 * 57 * This module validates predefined ACPI objects that appear in the namespace, 58 * at the time they are evaluated (via acpi_evaluate_object). The purpose of this 59 * validation is to detect problems with BIOS-exposed predefined ACPI objects 60 * before the results are returned to the ACPI-related drivers. 61 * 62 * There are several areas that are validated: 63 * 64 * 1) The number of input arguments as defined by the method/object in the 65 * ASL is validated against the ACPI specification. 66 * 2) The type of the return object (if any) is validated against the ACPI 67 * specification. 68 * 3) For returned package objects, the count of package elements is 69 * validated, as well as the type of each package element. Nested 70 * packages are supported. 71 * 72 * For any problems found, a warning message is issued. 73 * 74 ******************************************************************************/ 75/* Local prototypes */ 76static acpi_status 77acpi_ns_check_package(struct acpi_predefined_data *data, 78 union acpi_operand_object **return_object_ptr); 79 80static acpi_status 81acpi_ns_check_package_list(struct acpi_predefined_data *data, 82 const union acpi_predefined_info *package, 83 union acpi_operand_object **elements, u32 count); 84 85static acpi_status 86acpi_ns_check_package_elements(struct acpi_predefined_data *data, 87 union acpi_operand_object **elements, 88 u8 type1, 89 u32 count1, 90 u8 type2, u32 count2, u32 start_index); 91 92static acpi_status 93acpi_ns_check_object_type(struct acpi_predefined_data *data, 94 union acpi_operand_object **return_object_ptr, 95 u32 expected_btypes, u32 package_index); 96 97static acpi_status 98acpi_ns_check_reference(struct acpi_predefined_data *data, 99 union acpi_operand_object *return_object); 100 101static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes); 102 103/* 104 * Names for the types that can be returned by the predefined objects. 105 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs 106 */ 107static const char *acpi_rtype_names[] = { 108 "/Integer", 109 "/String", 110 "/Buffer", 111 "/Package", 112 "/Reference", 113}; 114 115/******************************************************************************* 116 * 117 * FUNCTION: acpi_ns_check_predefined_names 118 * 119 * PARAMETERS: Node - Namespace node for the method/object 120 * user_param_count - Number of parameters actually passed 121 * return_status - Status from the object evaluation 122 * return_object_ptr - Pointer to the object returned from the 123 * evaluation of a method or object 124 * 125 * RETURN: Status 126 * 127 * DESCRIPTION: Check an ACPI name for a match in the predefined name list. 128 * 129 ******************************************************************************/ 130 131acpi_status 132acpi_ns_check_predefined_names(struct acpi_namespace_node *node, 133 u32 user_param_count, 134 acpi_status return_status, 135 union acpi_operand_object **return_object_ptr) 136{ 137 union acpi_operand_object *return_object = *return_object_ptr; 138 acpi_status status = AE_OK; 139 const union acpi_predefined_info *predefined; 140 char *pathname; 141 struct acpi_predefined_data *data; 142 143 /* Match the name for this method/object against the predefined list */ 144 145 predefined = acpi_ns_check_for_predefined_name(node); 146 147 /* Get the full pathname to the object, for use in warning messages */ 148 149 pathname = acpi_ns_get_external_pathname(node); 150 if (!pathname) { 151 return AE_OK; /* Could not get pathname, ignore */ 152 } 153 154 /* 155 * Check that the parameter count for this method matches the ASL 156 * definition. For predefined names, ensure that both the caller and 157 * the method itself are in accordance with the ACPI specification. 158 */ 159 acpi_ns_check_parameter_count(pathname, node, user_param_count, 160 predefined); 161 162 /* If not a predefined name, we cannot validate the return object */ 163 164 if (!predefined) { 165 goto cleanup; 166 } 167 168 /* 169 * If the method failed or did not actually return an object, we cannot 170 * validate the return object 171 */ 172 if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) { 173 goto cleanup; 174 } 175 176 /* 177 * If there is no return value, check if we require a return value for 178 * this predefined name. Either one return value is expected, or none, 179 * for both methods and other objects. 180 * 181 * Exit now if there is no return object. Warning if one was expected. 182 */ 183 if (!return_object) { 184 if ((predefined->info.expected_btypes) && 185 (!(predefined->info.expected_btypes & ACPI_RTYPE_NONE))) { 186 ACPI_WARN_PREDEFINED((AE_INFO, pathname, 187 ACPI_WARN_ALWAYS, 188 "Missing expected return value")); 189 190 status = AE_AML_NO_RETURN_VALUE; 191 } 192 goto cleanup; 193 } 194 195 /* 196 * We have a return value, but if one wasn't expected, just exit, this is 197 * not a problem. For example, if the "Implicit Return" feature is 198 * enabled, methods will always return a value. 199 */ 200 if (!predefined->info.expected_btypes) { 201 goto cleanup; 202 } 203 204 /* Create the parameter data block for object validation */ 205 206 data = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_predefined_data)); 207 if (!data) { 208 goto cleanup; 209 } 210 data->predefined = predefined; 211 data->node_flags = node->flags; 212 data->pathname = pathname; 213 214 /* 215 * Check that the type of the return object is what is expected for 216 * this predefined name 217 */ 218 status = acpi_ns_check_object_type(data, return_object_ptr, 219 predefined->info.expected_btypes, 220 ACPI_NOT_PACKAGE_ELEMENT); 221 if (ACPI_FAILURE(status)) { 222 goto check_validation_status; 223 } 224 225 /* For returned Package objects, check the type of all sub-objects */ 226 227 if (return_object->common.type == ACPI_TYPE_PACKAGE) { 228 status = acpi_ns_check_package(data, return_object_ptr); 229 } 230 231check_validation_status: 232 /* 233 * If the object validation failed or if we successfully repaired one 234 * or more objects, mark the parent node to suppress further warning 235 * messages during the next evaluation of the same method/object. 236 */ 237 if (ACPI_FAILURE(status) || (data->flags & ACPI_OBJECT_REPAIRED)) { 238 node->flags |= ANOBJ_EVALUATED; 239 } 240 ACPI_FREE(data); 241 242cleanup: 243 ACPI_FREE(pathname); 244 return (status); 245} 246 247/******************************************************************************* 248 * 249 * FUNCTION: acpi_ns_check_parameter_count 250 * 251 * PARAMETERS: Pathname - Full pathname to the node (for error msgs) 252 * Node - Namespace node for the method/object 253 * user_param_count - Number of args passed in by the caller 254 * Predefined - Pointer to entry in predefined name table 255 * 256 * RETURN: None 257 * 258 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a 259 * predefined name is what is expected (i.e., what is defined in 260 * the ACPI specification for this predefined name.) 261 * 262 ******************************************************************************/ 263 264void 265acpi_ns_check_parameter_count(char *pathname, 266 struct acpi_namespace_node *node, 267 u32 user_param_count, 268 const union acpi_predefined_info *predefined) 269{ 270 u32 param_count; 271 u32 required_params_current; 272 u32 required_params_old; 273 274 /* Methods have 0-7 parameters. All other types have zero. */ 275 276 param_count = 0; 277 if (node->type == ACPI_TYPE_METHOD) { 278 param_count = node->object->method.param_count; 279 } 280 281 if (!predefined) { 282 /* 283 * Check the parameter count for non-predefined methods/objects. 284 * 285 * Warning if too few or too many arguments have been passed by the 286 * caller. An incorrect number of arguments may not cause the method 287 * to fail. However, the method will fail if there are too few 288 * arguments and the method attempts to use one of the missing ones. 289 */ 290 if (user_param_count < param_count) { 291 ACPI_WARN_PREDEFINED((AE_INFO, pathname, 292 ACPI_WARN_ALWAYS, 293 "Insufficient arguments - needs %u, found %u", 294 param_count, user_param_count)); 295 } else if (user_param_count > param_count) { 296 ACPI_WARN_PREDEFINED((AE_INFO, pathname, 297 ACPI_WARN_ALWAYS, 298 "Excess arguments - needs %u, found %u", 299 param_count, user_param_count)); 300 } 301 return; 302 } 303 304 /* 305 * Validate the user-supplied parameter count. 306 * Allow two different legal argument counts (_SCP, etc.) 307 */ 308 required_params_current = predefined->info.param_count & 0x0F; 309 required_params_old = predefined->info.param_count >> 4; 310 311 if (user_param_count != ACPI_UINT32_MAX) { 312 if ((user_param_count != required_params_current) && 313 (user_param_count != required_params_old)) { 314 ACPI_WARN_PREDEFINED((AE_INFO, pathname, 315 ACPI_WARN_ALWAYS, 316 "Parameter count mismatch - " 317 "caller passed %u, ACPI requires %u", 318 user_param_count, 319 required_params_current)); 320 } 321 } 322 323 /* 324 * Check that the ASL-defined parameter count is what is expected for 325 * this predefined name (parameter count as defined by the ACPI 326 * specification) 327 */ 328 if ((param_count != required_params_current) && 329 (param_count != required_params_old)) { 330 ACPI_WARN_PREDEFINED((AE_INFO, pathname, node->flags, 331 "Parameter count mismatch - ASL declared %u, ACPI requires %u", 332 param_count, required_params_current)); 333 } 334} 335 336/******************************************************************************* 337 * 338 * FUNCTION: acpi_ns_check_for_predefined_name 339 * 340 * PARAMETERS: Node - Namespace node for the method/object 341 * 342 * RETURN: Pointer to entry in predefined table. NULL indicates not found. 343 * 344 * DESCRIPTION: Check an object name against the predefined object list. 345 * 346 ******************************************************************************/ 347 348const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct 349 acpi_namespace_node 350 *node) 351{ 352 const union acpi_predefined_info *this_name; 353 354 /* Quick check for a predefined name, first character must be underscore */ 355 356 if (node->name.ascii[0] != '_') { 357 return (NULL); 358 } 359 360 /* Search info table for a predefined method/object name */ 361 362 this_name = predefined_names; 363 while (this_name->info.name[0]) { 364 if (ACPI_COMPARE_NAME(node->name.ascii, this_name->info.name)) { 365 return (this_name); 366 } 367 368 /* 369 * Skip next entry in the table if this name returns a Package 370 * (next entry contains the package info) 371 */ 372 if (this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) { 373 this_name++; 374 } 375 376 this_name++; 377 } 378 379 return (NULL); /* Not found */ 380} 381 382/******************************************************************************* 383 * 384 * FUNCTION: acpi_ns_check_package 385 * 386 * PARAMETERS: Data - Pointer to validation data structure 387 * return_object_ptr - Pointer to the object returned from the 388 * evaluation of a method or object 389 * 390 * RETURN: Status 391 * 392 * DESCRIPTION: Check a returned package object for the correct count and 393 * correct type of all sub-objects. 394 * 395 ******************************************************************************/ 396 397static acpi_status 398acpi_ns_check_package(struct acpi_predefined_data *data, 399 union acpi_operand_object **return_object_ptr) 400{ 401 union acpi_operand_object *return_object = *return_object_ptr; 402 const union acpi_predefined_info *package; 403 union acpi_operand_object **elements; 404 acpi_status status = AE_OK; 405 u32 expected_count; 406 u32 count; 407 u32 i; 408 409 ACPI_FUNCTION_NAME(ns_check_package); 410 411 /* The package info for this name is in the next table entry */ 412 413 package = data->predefined + 1; 414 415 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, 416 "%s Validating return Package of Type %X, Count %X\n", 417 data->pathname, package->ret_info.type, 418 return_object->package.count)); 419 420 /* Extract package count and elements array */ 421 422 elements = return_object->package.elements; 423 count = return_object->package.count; 424 425 /* The package must have at least one element, else invalid */ 426 427 if (!count) { 428 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 429 "Return Package has no elements (empty)")); 430 431 return (AE_AML_OPERAND_VALUE); 432 } 433 434 /* 435 * Decode the type of the expected package contents 436 * 437 * PTYPE1 packages contain no subpackages 438 * PTYPE2 packages contain sub-packages 439 */ 440 switch (package->ret_info.type) { 441 case ACPI_PTYPE1_FIXED: 442 443 /* 444 * The package count is fixed and there are no sub-packages 445 * 446 * If package is too small, exit. 447 * If package is larger than expected, issue warning but continue 448 */ 449 expected_count = 450 package->ret_info.count1 + package->ret_info.count2; 451 if (count < expected_count) { 452 goto package_too_small; 453 } else if (count > expected_count) { 454 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, 455 data->node_flags, 456 "Return Package is larger than needed - " 457 "found %u, expected %u", count, 458 expected_count)); 459 } 460 461 /* Validate all elements of the returned package */ 462 463 status = acpi_ns_check_package_elements(data, elements, 464 package->ret_info. 465 object_type1, 466 package->ret_info. 467 count1, 468 package->ret_info. 469 object_type2, 470 package->ret_info. 471 count2, 0); 472 break; 473 474 case ACPI_PTYPE1_VAR: 475 476 /* 477 * The package count is variable, there are no sub-packages, and all 478 * elements must be of the same type 479 */ 480 for (i = 0; i < count; i++) { 481 status = acpi_ns_check_object_type(data, elements, 482 package->ret_info. 483 object_type1, i); 484 if (ACPI_FAILURE(status)) { 485 return (status); 486 } 487 elements++; 488 } 489 break; 490 491 case ACPI_PTYPE1_OPTION: 492 493 /* 494 * The package count is variable, there are no sub-packages. There are 495 * a fixed number of required elements, and a variable number of 496 * optional elements. 497 * 498 * Check if package is at least as large as the minimum required 499 */ 500 expected_count = package->ret_info3.count; 501 if (count < expected_count) { 502 goto package_too_small; 503 } 504 505 /* Variable number of sub-objects */ 506 507 for (i = 0; i < count; i++) { 508 if (i < package->ret_info3.count) { 509 510 /* These are the required package elements (0, 1, or 2) */ 511 512 status = 513 acpi_ns_check_object_type(data, elements, 514 package-> 515 ret_info3. 516 object_type[i], 517 i); 518 if (ACPI_FAILURE(status)) { 519 return (status); 520 } 521 } else { 522 /* These are the optional package elements */ 523 524 status = 525 acpi_ns_check_object_type(data, elements, 526 package-> 527 ret_info3. 528 tail_object_type, 529 i); 530 if (ACPI_FAILURE(status)) { 531 return (status); 532 } 533 } 534 elements++; 535 } 536 break; 537 538 case ACPI_PTYPE2_REV_FIXED: 539 540 /* First element is the (Integer) revision */ 541 542 status = acpi_ns_check_object_type(data, elements, 543 ACPI_RTYPE_INTEGER, 0); 544 if (ACPI_FAILURE(status)) { 545 return (status); 546 } 547 548 elements++; 549 count--; 550 551 /* Examine the sub-packages */ 552 553 status = 554 acpi_ns_check_package_list(data, package, elements, count); 555 break; 556 557 case ACPI_PTYPE2_PKG_COUNT: 558 559 /* First element is the (Integer) count of sub-packages to follow */ 560 561 status = acpi_ns_check_object_type(data, elements, 562 ACPI_RTYPE_INTEGER, 0); 563 if (ACPI_FAILURE(status)) { 564 return (status); 565 } 566 567 /* 568 * Count cannot be larger than the parent package length, but allow it 569 * to be smaller. The >= accounts for the Integer above. 570 */ 571 expected_count = (u32) (*elements)->integer.value; 572 if (expected_count >= count) { 573 goto package_too_small; 574 } 575 576 count = expected_count; 577 elements++; 578 579 /* Examine the sub-packages */ 580 581 status = 582 acpi_ns_check_package_list(data, package, elements, count); 583 break; 584 585 case ACPI_PTYPE2: 586 case ACPI_PTYPE2_FIXED: 587 case ACPI_PTYPE2_MIN: 588 case ACPI_PTYPE2_COUNT: 589 590 /* 591 * These types all return a single Package that consists of a 592 * variable number of sub-Packages. 593 * 594 * First, ensure that the first element is a sub-Package. If not, 595 * the BIOS may have incorrectly returned the object as a single 596 * package instead of a Package of Packages (a common error if 597 * there is only one entry). We may be able to repair this by 598 * wrapping the returned Package with a new outer Package. 599 */ 600 if ((*elements)->common.type != ACPI_TYPE_PACKAGE) { 601 602 /* Create the new outer package and populate it */ 603 604 status = 605 acpi_ns_repair_package_list(data, 606 return_object_ptr); 607 if (ACPI_FAILURE(status)) { 608 return (status); 609 } 610 611 /* Update locals to point to the new package (of 1 element) */ 612 613 return_object = *return_object_ptr; 614 elements = return_object->package.elements; 615 count = 1; 616 } 617 618 /* Examine the sub-packages */ 619 620 status = 621 acpi_ns_check_package_list(data, package, elements, count); 622 break; 623 624 default: 625 626 /* Should not get here if predefined info table is correct */ 627 628 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 629 "Invalid internal return type in table entry: %X", 630 package->ret_info.type)); 631 632 return (AE_AML_INTERNAL); 633 } 634 635 return (status); 636 637package_too_small: 638 639 /* Error exit for the case with an incorrect package count */ 640 641 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 642 "Return Package is too small - found %u elements, expected %u", 643 count, expected_count)); 644 645 return (AE_AML_OPERAND_VALUE); 646} 647 648/******************************************************************************* 649 * 650 * FUNCTION: acpi_ns_check_package_list 651 * 652 * PARAMETERS: Data - Pointer to validation data structure 653 * Package - Pointer to package-specific info for method 654 * Elements - Element list of parent package. All elements 655 * of this list should be of type Package. 656 * Count - Count of subpackages 657 * 658 * RETURN: Status 659 * 660 * DESCRIPTION: Examine a list of subpackages 661 * 662 ******************************************************************************/ 663 664static acpi_status 665acpi_ns_check_package_list(struct acpi_predefined_data *data, 666 const union acpi_predefined_info *package, 667 union acpi_operand_object **elements, u32 count) 668{ 669 union acpi_operand_object *sub_package; 670 union acpi_operand_object **sub_elements; 671 acpi_status status; 672 u32 expected_count; 673 u32 i; 674 u32 j; 675 676 /* Validate each sub-Package in the parent Package */ 677 678 for (i = 0; i < count; i++) { 679 sub_package = *elements; 680 sub_elements = sub_package->package.elements; 681 682 /* Each sub-object must be of type Package */ 683 684 status = acpi_ns_check_object_type(data, &sub_package, 685 ACPI_RTYPE_PACKAGE, i); 686 if (ACPI_FAILURE(status)) { 687 return (status); 688 } 689 690 /* Examine the different types of expected sub-packages */ 691 692 switch (package->ret_info.type) { 693 case ACPI_PTYPE2: 694 case ACPI_PTYPE2_PKG_COUNT: 695 case ACPI_PTYPE2_REV_FIXED: 696 697 /* Each subpackage has a fixed number of elements */ 698 699 expected_count = 700 package->ret_info.count1 + package->ret_info.count2; 701 if (sub_package->package.count < expected_count) { 702 goto package_too_small; 703 } 704 705 status = 706 acpi_ns_check_package_elements(data, sub_elements, 707 package->ret_info. 708 object_type1, 709 package->ret_info. 710 count1, 711 package->ret_info. 712 object_type2, 713 package->ret_info. 714 count2, 0); 715 if (ACPI_FAILURE(status)) { 716 return (status); 717 } 718 break; 719 720 case ACPI_PTYPE2_FIXED: 721 722 /* Each sub-package has a fixed length */ 723 724 expected_count = package->ret_info2.count; 725 if (sub_package->package.count < expected_count) { 726 goto package_too_small; 727 } 728 729 /* Check the type of each sub-package element */ 730 731 for (j = 0; j < expected_count; j++) { 732 status = 733 acpi_ns_check_object_type(data, 734 &sub_elements[j], 735 package-> 736 ret_info2. 737 object_type[j], 738 j); 739 if (ACPI_FAILURE(status)) { 740 return (status); 741 } 742 } 743 break; 744 745 case ACPI_PTYPE2_MIN: 746 747 /* Each sub-package has a variable but minimum length */ 748 749 expected_count = package->ret_info.count1; 750 if (sub_package->package.count < expected_count) { 751 goto package_too_small; 752 } 753 754 /* Check the type of each sub-package element */ 755 756 status = 757 acpi_ns_check_package_elements(data, sub_elements, 758 package->ret_info. 759 object_type1, 760 sub_package->package. 761 count, 0, 0, 0); 762 if (ACPI_FAILURE(status)) { 763 return (status); 764 } 765 break; 766 767 case ACPI_PTYPE2_COUNT: 768 769 /* 770 * First element is the (Integer) count of elements, including 771 * the count field. 772 */ 773 status = acpi_ns_check_object_type(data, sub_elements, 774 ACPI_RTYPE_INTEGER, 775 0); 776 if (ACPI_FAILURE(status)) { 777 return (status); 778 } 779 780 /* 781 * Make sure package is large enough for the Count and is 782 * is as large as the minimum size 783 */ 784 expected_count = (u32)(*sub_elements)->integer.value; 785 if (sub_package->package.count < expected_count) { 786 goto package_too_small; 787 } 788 if (sub_package->package.count < 789 package->ret_info.count1) { 790 expected_count = package->ret_info.count1; 791 goto package_too_small; 792 } 793 794 /* Check the type of each sub-package element */ 795 796 status = 797 acpi_ns_check_package_elements(data, 798 (sub_elements + 1), 799 package->ret_info. 800 object_type1, 801 (expected_count - 1), 802 0, 0, 1); 803 if (ACPI_FAILURE(status)) { 804 return (status); 805 } 806 break; 807 808 default: /* Should not get here, type was validated by caller */ 809 810 return (AE_AML_INTERNAL); 811 } 812 813 elements++; 814 } 815 816 return (AE_OK); 817 818package_too_small: 819 820 /* The sub-package count was smaller than required */ 821 822 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 823 "Return Sub-Package[%u] is too small - found %u elements, expected %u", 824 i, sub_package->package.count, expected_count)); 825 826 return (AE_AML_OPERAND_VALUE); 827} 828 829/******************************************************************************* 830 * 831 * FUNCTION: acpi_ns_check_package_elements 832 * 833 * PARAMETERS: Data - Pointer to validation data structure 834 * Elements - Pointer to the package elements array 835 * Type1 - Object type for first group 836 * Count1 - Count for first group 837 * Type2 - Object type for second group 838 * Count2 - Count for second group 839 * start_index - Start of the first group of elements 840 * 841 * RETURN: Status 842 * 843 * DESCRIPTION: Check that all elements of a package are of the correct object 844 * type. Supports up to two groups of different object types. 845 * 846 ******************************************************************************/ 847 848static acpi_status 849acpi_ns_check_package_elements(struct acpi_predefined_data *data, 850 union acpi_operand_object **elements, 851 u8 type1, 852 u32 count1, 853 u8 type2, u32 count2, u32 start_index) 854{ 855 union acpi_operand_object **this_element = elements; 856 acpi_status status; 857 u32 i; 858 859 /* 860 * Up to two groups of package elements are supported by the data 861 * structure. All elements in each group must be of the same type. 862 * The second group can have a count of zero. 863 */ 864 for (i = 0; i < count1; i++) { 865 status = acpi_ns_check_object_type(data, this_element, 866 type1, i + start_index); 867 if (ACPI_FAILURE(status)) { 868 return (status); 869 } 870 this_element++; 871 } 872 873 for (i = 0; i < count2; i++) { 874 status = acpi_ns_check_object_type(data, this_element, 875 type2, 876 (i + count1 + start_index)); 877 if (ACPI_FAILURE(status)) { 878 return (status); 879 } 880 this_element++; 881 } 882 883 return (AE_OK); 884} 885 886/******************************************************************************* 887 * 888 * FUNCTION: acpi_ns_check_object_type 889 * 890 * PARAMETERS: Data - Pointer to validation data structure 891 * return_object_ptr - Pointer to the object returned from the 892 * evaluation of a method or object 893 * expected_btypes - Bitmap of expected return type(s) 894 * package_index - Index of object within parent package (if 895 * applicable - ACPI_NOT_PACKAGE_ELEMENT 896 * otherwise) 897 * 898 * RETURN: Status 899 * 900 * DESCRIPTION: Check the type of the return object against the expected object 901 * type(s). Use of Btype allows multiple expected object types. 902 * 903 ******************************************************************************/ 904 905static acpi_status 906acpi_ns_check_object_type(struct acpi_predefined_data *data, 907 union acpi_operand_object **return_object_ptr, 908 u32 expected_btypes, u32 package_index) 909{ 910 union acpi_operand_object *return_object = *return_object_ptr; 911 acpi_status status = AE_OK; 912 u32 return_btype; 913 char type_buffer[48]; /* Room for 5 types */ 914 915 /* 916 * If we get a NULL return_object here, it is a NULL package element, 917 * and this is always an error. 918 */ 919 if (!return_object) { 920 goto type_error_exit; 921 } 922 923 /* A Namespace node should not get here, but make sure */ 924 925 if (ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) { 926 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 927 "Invalid return type - Found a Namespace node [%4.4s] type %s", 928 return_object->node.name.ascii, 929 acpi_ut_get_type_name(return_object->node. 930 type))); 931 return (AE_AML_OPERAND_TYPE); 932 } 933 934 /* 935 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type. 936 * The bitmapped type allows multiple possible return types. 937 * 938 * Note, the cases below must handle all of the possible types returned 939 * from all of the predefined names (including elements of returned 940 * packages) 941 */ 942 switch (return_object->common.type) { 943 case ACPI_TYPE_INTEGER: 944 return_btype = ACPI_RTYPE_INTEGER; 945 break; 946 947 case ACPI_TYPE_BUFFER: 948 return_btype = ACPI_RTYPE_BUFFER; 949 break; 950 951 case ACPI_TYPE_STRING: 952 return_btype = ACPI_RTYPE_STRING; 953 break; 954 955 case ACPI_TYPE_PACKAGE: 956 return_btype = ACPI_RTYPE_PACKAGE; 957 break; 958 959 case ACPI_TYPE_LOCAL_REFERENCE: 960 return_btype = ACPI_RTYPE_REFERENCE; 961 break; 962 963 default: 964 /* Not one of the supported objects, must be incorrect */ 965 966 goto type_error_exit; 967 } 968 969 /* Is the object one of the expected types? */ 970 971 if (!(return_btype & expected_btypes)) { 972 973 /* Type mismatch -- attempt repair of the returned object */ 974 975 status = acpi_ns_repair_object(data, expected_btypes, 976 package_index, 977 return_object_ptr); 978 if (ACPI_SUCCESS(status)) { 979 return (AE_OK); /* Repair was successful */ 980 } 981 goto type_error_exit; 982 } 983 984 /* For reference objects, check that the reference type is correct */ 985 986 if (return_object->common.type == ACPI_TYPE_LOCAL_REFERENCE) { 987 status = acpi_ns_check_reference(data, return_object); 988 } 989 990 return (status); 991 992 type_error_exit: 993 994 /* Create a string with all expected types for this predefined object */ 995 996 acpi_ns_get_expected_types(type_buffer, expected_btypes); 997 998 if (package_index == ACPI_NOT_PACKAGE_ELEMENT) { 999 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 1000 "Return type mismatch - found %s, expected %s", 1001 acpi_ut_get_object_type_name 1002 (return_object), type_buffer)); 1003 } else { 1004 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 1005 "Return Package type mismatch at index %u - " 1006 "found %s, expected %s", package_index, 1007 acpi_ut_get_object_type_name 1008 (return_object), type_buffer)); 1009 } 1010 1011 return (AE_AML_OPERAND_TYPE); 1012} 1013 1014/******************************************************************************* 1015 * 1016 * FUNCTION: acpi_ns_check_reference 1017 * 1018 * PARAMETERS: Data - Pointer to validation data structure 1019 * return_object - Object returned from the evaluation of a 1020 * method or object 1021 * 1022 * RETURN: Status 1023 * 1024 * DESCRIPTION: Check a returned reference object for the correct reference 1025 * type. The only reference type that can be returned from a 1026 * predefined method is a named reference. All others are invalid. 1027 * 1028 ******************************************************************************/ 1029 1030static acpi_status 1031acpi_ns_check_reference(struct acpi_predefined_data *data, 1032 union acpi_operand_object *return_object) 1033{ 1034 1035 /* 1036 * Check the reference object for the correct reference type (opcode). 1037 * The only type of reference that can be converted to an union acpi_object is 1038 * a reference to a named object (reference class: NAME) 1039 */ 1040 if (return_object->reference.class == ACPI_REFCLASS_NAME) { 1041 return (AE_OK); 1042 } 1043 1044 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 1045 "Return type mismatch - unexpected reference object type [%s] %2.2X", 1046 acpi_ut_get_reference_name(return_object), 1047 return_object->reference.class)); 1048 1049 return (AE_AML_OPERAND_TYPE); 1050} 1051 1052/******************************************************************************* 1053 * 1054 * FUNCTION: acpi_ns_get_expected_types 1055 * 1056 * PARAMETERS: Buffer - Pointer to where the string is returned 1057 * expected_btypes - Bitmap of expected return type(s) 1058 * 1059 * RETURN: Buffer is populated with type names. 1060 * 1061 * DESCRIPTION: Translate the expected types bitmap into a string of ascii 1062 * names of expected types, for use in warning messages. 1063 * 1064 ******************************************************************************/ 1065 1066static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes) 1067{ 1068 u32 this_rtype; 1069 u32 i; 1070 u32 j; 1071 1072 j = 1; 1073 buffer[0] = 0; 1074 this_rtype = ACPI_RTYPE_INTEGER; 1075 1076 for (i = 0; i < ACPI_NUM_RTYPES; i++) { 1077 1078 /* If one of the expected types, concatenate the name of this type */ 1079 1080 if (expected_btypes & this_rtype) { 1081 ACPI_STRCAT(buffer, &acpi_rtype_names[i][j]); 1082 j = 0; /* Use name separator from now on */ 1083 } 1084 this_rtype <<= 1; /* Next Rtype */ 1085 } 1086} 1087