nspredef.c 35 KB

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