nspredef.c 34 KB

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