nspredef.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. /******************************************************************************
  2. *
  3. * Module Name: nspredef - Validation of ACPI predefined methods and objects
  4. * $Revision: 1.1 $
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2008, 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. #include <acpi/acpi.h>
  44. #include <acpi/acnamesp.h>
  45. #include <acpi/acpredef.h>
  46. #define _COMPONENT ACPI_NAMESPACE
  47. ACPI_MODULE_NAME("nspredef")
  48. /*******************************************************************************
  49. *
  50. * This module validates predefined ACPI objects that appear in the namespace,
  51. * at the time they are evaluated (via acpi_evaluate_object). The purpose of this
  52. * validation is to detect problems with BIOS-exposed predefined ACPI objects
  53. * before the results are returned to the ACPI-related drivers.
  54. *
  55. * There are several areas that are validated:
  56. *
  57. * 1) The number of input arguments as defined by the method/object in the
  58. * ASL is validated against the ACPI specification.
  59. * 2) The type of the return object (if any) is validated against the ACPI
  60. * specification.
  61. * 3) For returned package objects, the count of package elements is
  62. * validated, as well as the type of each package element. Nested
  63. * packages are supported.
  64. *
  65. * For any problems found, a warning message is issued.
  66. *
  67. ******************************************************************************/
  68. /* Local prototypes */
  69. static acpi_status
  70. acpi_ns_check_package(char *pathname,
  71. union acpi_operand_object *return_object,
  72. const union acpi_predefined_info *predefined);
  73. static acpi_status
  74. acpi_ns_check_package_elements(char *pathname,
  75. union acpi_operand_object **elements,
  76. u8 type1, u32 count1, u8 type2, u32 count2);
  77. static acpi_status
  78. acpi_ns_check_object_type(char *pathname,
  79. union acpi_operand_object *return_object,
  80. u32 expected_btypes, u32 package_index);
  81. static acpi_status
  82. acpi_ns_check_reference(char *pathname,
  83. union acpi_operand_object *return_object);
  84. /*
  85. * Names for the types that can be returned by the predefined objects.
  86. * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
  87. */
  88. static const char *acpi_rtype_names[] = {
  89. "/Integer",
  90. "/String",
  91. "/Buffer",
  92. "/Package",
  93. "/Reference",
  94. };
  95. #define ACPI_NOT_PACKAGE ACPI_UINT32_MAX
  96. /*******************************************************************************
  97. *
  98. * FUNCTION: acpi_ns_check_predefined_names
  99. *
  100. * PARAMETERS: Node - Namespace node for the method/object
  101. * return_object - Object returned from the evaluation of this
  102. * method/object
  103. *
  104. * RETURN: Status
  105. *
  106. * DESCRIPTION: Check an ACPI name for a match in the predefined name list.
  107. *
  108. ******************************************************************************/
  109. acpi_status
  110. acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
  111. union acpi_operand_object *return_object)
  112. {
  113. acpi_status status = AE_OK;
  114. const union acpi_predefined_info *predefined;
  115. char *pathname;
  116. /* Match the name for this method/object against the predefined list */
  117. predefined = acpi_ns_check_for_predefined_name(node);
  118. if (!predefined) {
  119. /* Name was not one of the predefined names */
  120. return (AE_OK);
  121. }
  122. /* Get the full pathname to the object, for use in error messages */
  123. pathname = acpi_ns_get_external_pathname(node);
  124. if (!pathname) {
  125. pathname = ACPI_CAST_PTR(char, predefined->info.name);
  126. }
  127. /*
  128. * Check that the parameter count for this method is in accordance
  129. * with the ACPI specification.
  130. */
  131. acpi_ns_check_parameter_count(pathname, node, predefined);
  132. /*
  133. * If there is no return value, check if we require a return value for
  134. * this predefined name. Either one return value is expected, or none,
  135. * for both methods and other objects.
  136. *
  137. * Exit now if there is no return object. Warning if one was expected.
  138. */
  139. if (!return_object) {
  140. if ((predefined->info.expected_btypes) &&
  141. (!(predefined->info.expected_btypes & ACPI_RTYPE_NONE))) {
  142. ACPI_ERROR((AE_INFO,
  143. "%s: Missing expected return value",
  144. pathname));
  145. status = AE_AML_NO_RETURN_VALUE;
  146. }
  147. goto exit;
  148. }
  149. /*
  150. * We have a return value, but if one wasn't expected, just exit, this is
  151. * not a problem
  152. *
  153. * For example, if "Implicit return value" is enabled, methods will
  154. * always return a value
  155. */
  156. if (!predefined->info.expected_btypes) {
  157. goto exit;
  158. }
  159. /*
  160. * Check that the type of the return object is what is expected for
  161. * this predefined name
  162. */
  163. status = acpi_ns_check_object_type(pathname, return_object,
  164. predefined->info.expected_btypes,
  165. ACPI_NOT_PACKAGE);
  166. if (ACPI_FAILURE(status)) {
  167. goto exit;
  168. }
  169. /* For returned Package objects, check the type of all sub-objects */
  170. if (ACPI_GET_OBJECT_TYPE(return_object) == ACPI_TYPE_PACKAGE) {
  171. status =
  172. acpi_ns_check_package(pathname, return_object, predefined);
  173. }
  174. exit:
  175. if (pathname) {
  176. ACPI_FREE(pathname);
  177. }
  178. return (status);
  179. }
  180. /*******************************************************************************
  181. *
  182. * FUNCTION: acpi_ns_check_parameter_count
  183. *
  184. * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
  185. * Node - Namespace node for the method/object
  186. * Predefined - Pointer to entry in predefined name table
  187. *
  188. * RETURN: None
  189. *
  190. * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
  191. * predefined name is what is expected (i.e., what is defined in
  192. * the ACPI specification for this predefined name.)
  193. *
  194. ******************************************************************************/
  195. void
  196. acpi_ns_check_parameter_count(char *pathname,
  197. struct acpi_namespace_node *node,
  198. const union acpi_predefined_info *predefined)
  199. {
  200. u32 param_count;
  201. u32 required_params_current;
  202. u32 required_params_old;
  203. /*
  204. * Check that the ASL-defined parameter count is what is expected for
  205. * this predefined name.
  206. *
  207. * Methods have 0-7 parameters. All other types have zero.
  208. */
  209. param_count = 0;
  210. if (node->type == ACPI_TYPE_METHOD) {
  211. param_count = node->object->method.param_count;
  212. }
  213. /* Validate parameter count - allow two different legal counts (_SCP) */
  214. required_params_current = predefined->info.param_count & 0x0F;
  215. required_params_old = predefined->info.param_count >> 4;
  216. if ((param_count != required_params_current) &&
  217. (param_count != required_params_old)) {
  218. ACPI_WARNING((AE_INFO,
  219. "%s: Parameter count mismatch - ASL declared %d, expected %d",
  220. pathname, param_count, required_params_current));
  221. }
  222. }
  223. /*******************************************************************************
  224. *
  225. * FUNCTION: acpi_ns_check_for_predefined_name
  226. *
  227. * PARAMETERS: Node - Namespace node for the method/object
  228. *
  229. * RETURN: Pointer to entry in predefined table. NULL indicates not found.
  230. *
  231. * DESCRIPTION: Check an object name against the predefined object list.
  232. *
  233. ******************************************************************************/
  234. const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct
  235. acpi_namespace_node
  236. *node)
  237. {
  238. const union acpi_predefined_info *this_name;
  239. /* Quick check for a predefined name, first character must be underscore */
  240. if (node->name.ascii[0] != '_') {
  241. return (NULL);
  242. }
  243. /* Search info table for a predefined method/object name */
  244. this_name = predefined_names;
  245. while (this_name->info.name[0]) {
  246. if (ACPI_COMPARE_NAME(node->name.ascii, this_name->info.name)) {
  247. /* Return pointer to this table entry */
  248. return (this_name);
  249. }
  250. /*
  251. * Skip next entry in the table if this name returns a Package
  252. * (next entry contains the package info)
  253. */
  254. if (this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) {
  255. this_name++;
  256. }
  257. this_name++;
  258. }
  259. return (NULL);
  260. }
  261. /*******************************************************************************
  262. *
  263. * FUNCTION: acpi_ns_check_package
  264. *
  265. * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
  266. * return_object - Object returned from the evaluation of a
  267. * method or object
  268. * Predefined - Pointer to entry in predefined name table
  269. *
  270. * RETURN: Status
  271. *
  272. * DESCRIPTION: Check a returned package object for the correct count and
  273. * correct type of all sub-objects.
  274. *
  275. ******************************************************************************/
  276. static acpi_status
  277. acpi_ns_check_package(char *pathname,
  278. union acpi_operand_object *return_object,
  279. const union acpi_predefined_info *predefined)
  280. {
  281. const union acpi_predefined_info *package;
  282. union acpi_operand_object *sub_package;
  283. union acpi_operand_object **elements;
  284. union acpi_operand_object **sub_elements;
  285. acpi_status status;
  286. u32 expected_count;
  287. u32 count;
  288. u32 i;
  289. u32 j;
  290. ACPI_FUNCTION_NAME(ns_check_package);
  291. /* The package info for this name is in the next table entry */
  292. package = predefined + 1;
  293. ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
  294. "%s Validating return Package of Type %X, Count %X\n",
  295. pathname, package->ret_info.type,
  296. return_object->package.count));
  297. /* Extract package count and elements array */
  298. elements = return_object->package.elements;
  299. count = return_object->package.count;
  300. /* The package must have at least one element, else invalid */
  301. if (!count) {
  302. ACPI_WARNING((AE_INFO,
  303. "%s: Return Package has no elements (empty)",
  304. pathname));
  305. return (AE_AML_OPERAND_VALUE);
  306. }
  307. /*
  308. * Decode the type of the expected package contents
  309. *
  310. * PTYPE1 packages contain no subpackages
  311. * PTYPE2 packages contain sub-packages
  312. */
  313. switch (package->ret_info.type) {
  314. case ACPI_PTYPE1_FIXED:
  315. /*
  316. * The package count is fixed and there are no sub-packages
  317. *
  318. * If package is too small, exit.
  319. * If package is larger than expected, issue warning but continue
  320. */
  321. expected_count =
  322. package->ret_info.count1 + package->ret_info.count2;
  323. if (count < expected_count) {
  324. goto package_too_small;
  325. } else if (count > expected_count) {
  326. ACPI_WARNING((AE_INFO,
  327. "%s: Return Package is larger than needed - "
  328. "found %u, expected %u", pathname, count,
  329. expected_count));
  330. }
  331. /* Validate all elements of the returned package */
  332. status = acpi_ns_check_package_elements(pathname, elements,
  333. package->ret_info.
  334. object_type1,
  335. package->ret_info.
  336. count1,
  337. package->ret_info.
  338. object_type2,
  339. package->ret_info.
  340. count2);
  341. if (ACPI_FAILURE(status)) {
  342. return (status);
  343. }
  344. break;
  345. case ACPI_PTYPE1_VAR:
  346. /*
  347. * The package count is variable, there are no sub-packages, and all
  348. * elements must be of the same type
  349. */
  350. for (i = 0; i < count; i++) {
  351. status = acpi_ns_check_object_type(pathname, *elements,
  352. package->ret_info.
  353. object_type1, i);
  354. if (ACPI_FAILURE(status)) {
  355. return (status);
  356. }
  357. elements++;
  358. }
  359. break;
  360. case ACPI_PTYPE1_OPTION:
  361. /*
  362. * The package count is variable, there are no sub-packages. There are
  363. * a fixed number of required elements, and a variable number of
  364. * optional elements.
  365. *
  366. * Check if package is at least as large as the minimum required
  367. */
  368. expected_count = package->ret_info3.count;
  369. if (count < expected_count) {
  370. goto package_too_small;
  371. }
  372. /* Variable number of sub-objects */
  373. for (i = 0; i < count; i++) {
  374. if (i < package->ret_info3.count) {
  375. /* These are the required package elements (0, 1, or 2) */
  376. status =
  377. acpi_ns_check_object_type(pathname,
  378. *elements,
  379. package->
  380. ret_info3.
  381. object_type[i],
  382. i);
  383. if (ACPI_FAILURE(status)) {
  384. return (status);
  385. }
  386. } else {
  387. /* These are the optional package elements */
  388. status =
  389. acpi_ns_check_object_type(pathname,
  390. *elements,
  391. package->
  392. ret_info3.
  393. tail_object_type,
  394. i);
  395. if (ACPI_FAILURE(status)) {
  396. return (status);
  397. }
  398. }
  399. elements++;
  400. }
  401. break;
  402. case ACPI_PTYPE2_PKG_COUNT:
  403. /* First element is the (Integer) count of sub-packages to follow */
  404. status = acpi_ns_check_object_type(pathname, *elements,
  405. ACPI_RTYPE_INTEGER, 0);
  406. if (ACPI_FAILURE(status)) {
  407. return (status);
  408. }
  409. /*
  410. * Count cannot be larger than the parent package length, but allow it
  411. * to be smaller. The >= accounts for the Integer above.
  412. */
  413. expected_count = (u32) (*elements)->integer.value;
  414. if (expected_count >= count) {
  415. goto package_too_small;
  416. }
  417. count = expected_count;
  418. elements++;
  419. /* Now we can walk the sub-packages */
  420. /*lint -fallthrough */
  421. case ACPI_PTYPE2:
  422. case ACPI_PTYPE2_FIXED:
  423. case ACPI_PTYPE2_MIN:
  424. case ACPI_PTYPE2_COUNT:
  425. /*
  426. * These types all return a single package that consists of a variable
  427. * number of sub-packages
  428. */
  429. for (i = 0; i < count; i++) {
  430. sub_package = *elements;
  431. sub_elements = sub_package->package.elements;
  432. /* Each sub-object must be of type Package */
  433. status =
  434. acpi_ns_check_object_type(pathname, sub_package,
  435. ACPI_RTYPE_PACKAGE, i);
  436. if (ACPI_FAILURE(status)) {
  437. return (status);
  438. }
  439. /* Examine the different types of sub-packages */
  440. switch (package->ret_info.type) {
  441. case ACPI_PTYPE2:
  442. case ACPI_PTYPE2_PKG_COUNT:
  443. /* Each subpackage has a fixed number of elements */
  444. expected_count =
  445. package->ret_info.count1 +
  446. package->ret_info.count2;
  447. if (sub_package->package.count !=
  448. expected_count) {
  449. count = sub_package->package.count;
  450. goto package_too_small;
  451. }
  452. status =
  453. acpi_ns_check_package_elements(pathname,
  454. sub_elements,
  455. package->
  456. ret_info.
  457. object_type1,
  458. package->
  459. ret_info.
  460. count1,
  461. package->
  462. ret_info.
  463. object_type2,
  464. package->
  465. ret_info.
  466. count2);
  467. if (ACPI_FAILURE(status)) {
  468. return (status);
  469. }
  470. break;
  471. case ACPI_PTYPE2_FIXED:
  472. /* Each sub-package has a fixed length */
  473. expected_count = package->ret_info2.count;
  474. if (sub_package->package.count < expected_count) {
  475. count = sub_package->package.count;
  476. goto package_too_small;
  477. }
  478. /* Check the type of each sub-package element */
  479. for (j = 0; j < expected_count; j++) {
  480. status =
  481. acpi_ns_check_object_type(pathname,
  482. sub_elements
  483. [j],
  484. package->
  485. ret_info2.
  486. object_type
  487. [j], j);
  488. if (ACPI_FAILURE(status)) {
  489. return (status);
  490. }
  491. }
  492. break;
  493. case ACPI_PTYPE2_MIN:
  494. /* Each sub-package has a variable but minimum length */
  495. expected_count = package->ret_info.count1;
  496. if (sub_package->package.count < expected_count) {
  497. count = sub_package->package.count;
  498. goto package_too_small;
  499. }
  500. /* Check the type of each sub-package element */
  501. status =
  502. acpi_ns_check_package_elements(pathname,
  503. sub_elements,
  504. package->
  505. ret_info.
  506. object_type1,
  507. sub_package->
  508. package.
  509. count, 0, 0);
  510. if (ACPI_FAILURE(status)) {
  511. return (status);
  512. }
  513. break;
  514. case ACPI_PTYPE2_COUNT:
  515. /* First element is the (Integer) count of elements to follow */
  516. status =
  517. acpi_ns_check_object_type(pathname,
  518. *sub_elements,
  519. ACPI_RTYPE_INTEGER,
  520. 0);
  521. if (ACPI_FAILURE(status)) {
  522. return (status);
  523. }
  524. /* Make sure package is large enough for the Count */
  525. expected_count =
  526. (u32) (*sub_elements)->integer.value;
  527. if (sub_package->package.count < expected_count) {
  528. count = sub_package->package.count;
  529. goto package_too_small;
  530. }
  531. /* Check the type of each sub-package element */
  532. status =
  533. acpi_ns_check_package_elements(pathname,
  534. (sub_elements
  535. + 1),
  536. package->
  537. ret_info.
  538. object_type1,
  539. (expected_count
  540. - 1), 0, 0);
  541. if (ACPI_FAILURE(status)) {
  542. return (status);
  543. }
  544. break;
  545. default:
  546. break;
  547. }
  548. elements++;
  549. }
  550. break;
  551. default:
  552. /* Should not get here if predefined info table is correct */
  553. ACPI_WARNING((AE_INFO,
  554. "%s: Invalid internal return type in table entry: %X",
  555. pathname, package->ret_info.type));
  556. return (AE_AML_INTERNAL);
  557. }
  558. return (AE_OK);
  559. package_too_small:
  560. /* Error exit for the case with an incorrect package count */
  561. ACPI_WARNING((AE_INFO, "%s: Return Package is too small - "
  562. "found %u, expected %u", pathname, count,
  563. expected_count));
  564. return (AE_AML_OPERAND_VALUE);
  565. }
  566. /*******************************************************************************
  567. *
  568. * FUNCTION: acpi_ns_check_package_elements
  569. *
  570. * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
  571. * Elements - Pointer to the package elements array
  572. * Type1 - Object type for first group
  573. * Count1 - Count for first group
  574. * Type2 - Object type for second group
  575. * Count2 - Count for second group
  576. *
  577. * RETURN: Status
  578. *
  579. * DESCRIPTION: Check that all elements of a package are of the correct object
  580. * type. Supports up to two groups of different object types.
  581. *
  582. ******************************************************************************/
  583. static acpi_status
  584. acpi_ns_check_package_elements(char *pathname,
  585. union acpi_operand_object **elements,
  586. u8 type1, u32 count1, u8 type2, u32 count2)
  587. {
  588. union acpi_operand_object **this_element = elements;
  589. acpi_status status;
  590. u32 i;
  591. /*
  592. * Up to two groups of package elements are supported by the data
  593. * structure. All elements in each group must be of the same type.
  594. * The second group can have a count of zero.
  595. */
  596. for (i = 0; i < count1; i++) {
  597. status = acpi_ns_check_object_type(pathname, *this_element,
  598. type1, i);
  599. if (ACPI_FAILURE(status)) {
  600. return (status);
  601. }
  602. this_element++;
  603. }
  604. for (i = 0; i < count2; i++) {
  605. status = acpi_ns_check_object_type(pathname, *this_element,
  606. type2, (i + count1));
  607. if (ACPI_FAILURE(status)) {
  608. return (status);
  609. }
  610. this_element++;
  611. }
  612. return (AE_OK);
  613. }
  614. /*******************************************************************************
  615. *
  616. * FUNCTION: acpi_ns_check_object_type
  617. *
  618. * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
  619. * return_object - Object return from the execution of this
  620. * method/object
  621. * expected_btypes - Bitmap of expected return type(s)
  622. * package_index - Index of object within parent package (if
  623. * applicable - ACPI_NOT_PACKAGE otherwise)
  624. *
  625. * RETURN: Status
  626. *
  627. * DESCRIPTION: Check the type of the return object against the expected object
  628. * type(s). Use of Btype allows multiple expected object types.
  629. *
  630. ******************************************************************************/
  631. static acpi_status
  632. acpi_ns_check_object_type(char *pathname,
  633. union acpi_operand_object *return_object,
  634. u32 expected_btypes, u32 package_index)
  635. {
  636. acpi_status status = AE_OK;
  637. u32 return_btype;
  638. char type_buffer[48]; /* Room for 5 types */
  639. u32 this_rtype;
  640. u32 i;
  641. u32 j;
  642. /*
  643. * If we get a NULL return_object here, it is a NULL package element,
  644. * and this is always an error.
  645. */
  646. if (!return_object) {
  647. goto type_error_exit;
  648. }
  649. /* A Namespace node should not get here, but make sure */
  650. if (ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
  651. ACPI_WARNING((AE_INFO,
  652. "%s: Invalid return type - Found a Namespace node [%4.4s] type %s",
  653. pathname, return_object->node.name.ascii,
  654. acpi_ut_get_type_name(return_object->node.type)));
  655. return (AE_AML_OPERAND_TYPE);
  656. }
  657. /*
  658. * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
  659. * The bitmapped type allows multiple possible return types.
  660. *
  661. * Note, the cases below must handle all of the possible types returned
  662. * from all of the predefined names (including elements of returned
  663. * packages)
  664. */
  665. switch (ACPI_GET_OBJECT_TYPE(return_object)) {
  666. case ACPI_TYPE_INTEGER:
  667. return_btype = ACPI_RTYPE_INTEGER;
  668. break;
  669. case ACPI_TYPE_BUFFER:
  670. return_btype = ACPI_RTYPE_BUFFER;
  671. break;
  672. case ACPI_TYPE_STRING:
  673. return_btype = ACPI_RTYPE_STRING;
  674. break;
  675. case ACPI_TYPE_PACKAGE:
  676. return_btype = ACPI_RTYPE_PACKAGE;
  677. break;
  678. case ACPI_TYPE_LOCAL_REFERENCE:
  679. return_btype = ACPI_RTYPE_REFERENCE;
  680. break;
  681. default:
  682. /* Not one of the supported objects, must be incorrect */
  683. goto type_error_exit;
  684. }
  685. /* Is the object one of the expected types? */
  686. if (!(return_btype & expected_btypes)) {
  687. goto type_error_exit;
  688. }
  689. /* For reference objects, check that the reference type is correct */
  690. if (ACPI_GET_OBJECT_TYPE(return_object) == ACPI_TYPE_LOCAL_REFERENCE) {
  691. status = acpi_ns_check_reference(pathname, return_object);
  692. }
  693. return (status);
  694. type_error_exit:
  695. /* Create a string with all expected types for this predefined object */
  696. j = 1;
  697. type_buffer[0] = 0;
  698. this_rtype = ACPI_RTYPE_INTEGER;
  699. for (i = 0; i < ACPI_NUM_RTYPES; i++) {
  700. /* If one of the expected types, concatenate the name of this type */
  701. if (expected_btypes & this_rtype) {
  702. ACPI_STRCAT(type_buffer, &acpi_rtype_names[i][j]);
  703. j = 0; /* Use name separator from now on */
  704. }
  705. this_rtype <<= 1; /* Next Rtype */
  706. }
  707. if (package_index == ACPI_NOT_PACKAGE) {
  708. ACPI_WARNING((AE_INFO,
  709. "%s: Return type mismatch - found %s, expected %s",
  710. pathname,
  711. acpi_ut_get_object_type_name(return_object),
  712. type_buffer));
  713. } else {
  714. ACPI_WARNING((AE_INFO,
  715. "%s: Return Package type mismatch at index %u - "
  716. "found %s, expected %s", pathname, package_index,
  717. acpi_ut_get_object_type_name(return_object),
  718. type_buffer));
  719. }
  720. return (AE_AML_OPERAND_TYPE);
  721. }
  722. /*******************************************************************************
  723. *
  724. * FUNCTION: acpi_ns_check_reference
  725. *
  726. * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
  727. * return_object - Object returned from the evaluation of a
  728. * method or object
  729. *
  730. * RETURN: Status
  731. *
  732. * DESCRIPTION: Check a returned reference object for the correct reference
  733. * type. The only reference type that can be returned from a
  734. * predefined method is a named reference. All others are invalid.
  735. *
  736. ******************************************************************************/
  737. static acpi_status
  738. acpi_ns_check_reference(char *pathname,
  739. union acpi_operand_object *return_object)
  740. {
  741. /*
  742. * Check the reference object for the correct reference type (opcode).
  743. * The only type of reference that can be converted to an union acpi_object is
  744. * a reference to a named object (reference class: NAME)
  745. */
  746. if (return_object->reference.class == ACPI_REFCLASS_NAME) {
  747. return (AE_OK);
  748. }
  749. ACPI_WARNING((AE_INFO,
  750. "%s: Return type mismatch - unexpected reference object type [%s] %2.2X",
  751. pathname, acpi_ut_get_reference_name(return_object),
  752. return_object->reference.class));
  753. return (AE_AML_OPERAND_TYPE);
  754. }