nspredef.c 33 KB

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