nspredef.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  1. /******************************************************************************
  2. *
  3. * Module Name: nspredef - Validation of ACPI predefined methods and objects
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #define ACPI_CREATE_PREDEFINED_TABLE
  43. #include <acpi/acpi.h>
  44. #include "accommon.h"
  45. #include "acnamesp.h"
  46. #include "acpredef.h"
  47. #define _COMPONENT ACPI_NAMESPACE
  48. ACPI_MODULE_NAME("nspredef")
  49. /*******************************************************************************
  50. *
  51. * This module validates predefined ACPI objects that appear in the namespace,
  52. * at the time they are evaluated (via acpi_evaluate_object). The purpose of this
  53. * validation is to detect problems with BIOS-exposed predefined ACPI objects
  54. * before the results are returned to the ACPI-related drivers.
  55. *
  56. * There are several areas that are validated:
  57. *
  58. * 1) The number of input arguments as defined by the method/object in the
  59. * ASL is validated against the ACPI specification.
  60. * 2) The type of the return object (if any) is validated against the ACPI
  61. * specification.
  62. * 3) For returned package objects, the count of package elements is
  63. * validated, as well as the type of each package element. Nested
  64. * packages are supported.
  65. *
  66. * For any problems found, a warning message is issued.
  67. *
  68. ******************************************************************************/
  69. /* Local prototypes */
  70. static acpi_status
  71. acpi_ns_check_package(struct acpi_predefined_data *data,
  72. union acpi_operand_object **return_object_ptr);
  73. static acpi_status
  74. acpi_ns_check_package_list(struct acpi_predefined_data *data,
  75. const union acpi_predefined_info *package,
  76. union acpi_operand_object **elements, u32 count);
  77. static acpi_status
  78. acpi_ns_check_package_elements(struct acpi_predefined_data *data,
  79. union acpi_operand_object **elements,
  80. u8 type1,
  81. u32 count1,
  82. u8 type2, u32 count2, u32 start_index);
  83. static acpi_status
  84. acpi_ns_check_object_type(struct acpi_predefined_data *data,
  85. union acpi_operand_object **return_object_ptr,
  86. u32 expected_btypes, u32 package_index);
  87. static acpi_status
  88. acpi_ns_check_reference(struct acpi_predefined_data *data,
  89. union acpi_operand_object *return_object);
  90. static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes);
  91. /*
  92. * Names for the types that can be returned by the predefined objects.
  93. * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
  94. */
  95. static const char *acpi_rtype_names[] = {
  96. "/Integer",
  97. "/String",
  98. "/Buffer",
  99. "/Package",
  100. "/Reference",
  101. };
  102. /*******************************************************************************
  103. *
  104. * FUNCTION: acpi_ns_check_predefined_names
  105. *
  106. * PARAMETERS: node - Namespace node for the method/object
  107. * user_param_count - Number of parameters actually passed
  108. * return_status - Status from the object evaluation
  109. * return_object_ptr - Pointer to the object returned from the
  110. * evaluation of a method or object
  111. *
  112. * RETURN: Status
  113. *
  114. * DESCRIPTION: Check an ACPI name for a match in the predefined name list.
  115. *
  116. ******************************************************************************/
  117. acpi_status
  118. acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
  119. u32 user_param_count,
  120. acpi_status return_status,
  121. union acpi_operand_object **return_object_ptr)
  122. {
  123. union acpi_operand_object *return_object = *return_object_ptr;
  124. acpi_status status = AE_OK;
  125. const union acpi_predefined_info *predefined;
  126. char *pathname;
  127. struct acpi_predefined_data *data;
  128. /* Match the name for this method/object against the predefined list */
  129. predefined = acpi_ns_check_for_predefined_name(node);
  130. /* Get the full pathname to the object, for use in warning messages */
  131. pathname = acpi_ns_get_external_pathname(node);
  132. if (!pathname) {
  133. return AE_OK; /* Could not get pathname, ignore */
  134. }
  135. /*
  136. * Check that the parameter count for this method matches the ASL
  137. * definition. For predefined names, ensure that both the caller and
  138. * the method itself are in accordance with the ACPI specification.
  139. */
  140. acpi_ns_check_parameter_count(pathname, node, user_param_count,
  141. predefined);
  142. /* If not a predefined name, we cannot validate the return object */
  143. if (!predefined) {
  144. goto cleanup;
  145. }
  146. /*
  147. * If the method failed or did not actually return an object, we cannot
  148. * validate the return object
  149. */
  150. if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) {
  151. goto cleanup;
  152. }
  153. /*
  154. * If there is no return value, check if we require a return value for
  155. * this predefined name. Either one return value is expected, or none,
  156. * for both methods and other objects.
  157. *
  158. * Exit now if there is no return object. Warning if one was expected.
  159. */
  160. if (!return_object) {
  161. if ((predefined->info.expected_btypes) &&
  162. (!(predefined->info.expected_btypes & ACPI_RTYPE_NONE))) {
  163. ACPI_WARN_PREDEFINED((AE_INFO, pathname,
  164. ACPI_WARN_ALWAYS,
  165. "Missing expected return value"));
  166. status = AE_AML_NO_RETURN_VALUE;
  167. }
  168. goto cleanup;
  169. }
  170. /*
  171. * Return value validation and possible repair.
  172. *
  173. * 1) Don't perform return value validation/repair if this feature
  174. * has been disabled via a global option.
  175. *
  176. * 2) We have a return value, but if one wasn't expected, just exit,
  177. * this is not a problem. For example, if the "Implicit Return"
  178. * feature is enabled, methods will always return a value.
  179. *
  180. * 3) If the return value can be of any type, then we cannot perform
  181. * any validation, just exit.
  182. */
  183. if (acpi_gbl_disable_auto_repair ||
  184. (!predefined->info.expected_btypes) ||
  185. (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) {
  186. goto cleanup;
  187. }
  188. /* Create the parameter data block for object validation */
  189. data = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_predefined_data));
  190. if (!data) {
  191. goto cleanup;
  192. }
  193. data->predefined = predefined;
  194. data->node = node;
  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. case ACPI_PTYPE2_FIX_VAR:
  536. /*
  537. * These types all return a single Package that consists of a
  538. * variable number of sub-Packages.
  539. *
  540. * First, ensure that the first element is a sub-Package. If not,
  541. * the BIOS may have incorrectly returned the object as a single
  542. * package instead of a Package of Packages (a common error if
  543. * there is only one entry). We may be able to repair this by
  544. * wrapping the returned Package with a new outer Package.
  545. */
  546. if (*elements
  547. && ((*elements)->common.type != ACPI_TYPE_PACKAGE)) {
  548. /* Create the new outer package and populate it */
  549. status =
  550. acpi_ns_wrap_with_package(data, return_object,
  551. return_object_ptr);
  552. if (ACPI_FAILURE(status)) {
  553. return (status);
  554. }
  555. /* Update locals to point to the new package (of 1 element) */
  556. return_object = *return_object_ptr;
  557. elements = return_object->package.elements;
  558. count = 1;
  559. }
  560. /* Examine the sub-packages */
  561. status =
  562. acpi_ns_check_package_list(data, package, elements, count);
  563. break;
  564. default:
  565. /* Should not get here if predefined info table is correct */
  566. ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
  567. "Invalid internal return type in table entry: %X",
  568. package->ret_info.type));
  569. return (AE_AML_INTERNAL);
  570. }
  571. return (status);
  572. package_too_small:
  573. /* Error exit for the case with an incorrect package count */
  574. ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
  575. "Return Package is too small - found %u elements, expected %u",
  576. count, expected_count));
  577. return (AE_AML_OPERAND_VALUE);
  578. }
  579. /*******************************************************************************
  580. *
  581. * FUNCTION: acpi_ns_check_package_list
  582. *
  583. * PARAMETERS: data - Pointer to validation data structure
  584. * package - Pointer to package-specific info for method
  585. * elements - Element list of parent package. All elements
  586. * of this list should be of type Package.
  587. * count - Count of subpackages
  588. *
  589. * RETURN: Status
  590. *
  591. * DESCRIPTION: Examine a list of subpackages
  592. *
  593. ******************************************************************************/
  594. static acpi_status
  595. acpi_ns_check_package_list(struct acpi_predefined_data *data,
  596. const union acpi_predefined_info *package,
  597. union acpi_operand_object **elements, u32 count)
  598. {
  599. union acpi_operand_object *sub_package;
  600. union acpi_operand_object **sub_elements;
  601. acpi_status status;
  602. u32 expected_count;
  603. u32 i;
  604. u32 j;
  605. /*
  606. * Validate each sub-Package in the parent Package
  607. *
  608. * NOTE: assumes list of sub-packages contains no NULL elements.
  609. * Any NULL elements should have been removed by earlier call
  610. * to acpi_ns_remove_null_elements.
  611. */
  612. for (i = 0; i < count; i++) {
  613. sub_package = *elements;
  614. sub_elements = sub_package->package.elements;
  615. data->parent_package = sub_package;
  616. /* Each sub-object must be of type Package */
  617. status = acpi_ns_check_object_type(data, &sub_package,
  618. ACPI_RTYPE_PACKAGE, i);
  619. if (ACPI_FAILURE(status)) {
  620. return (status);
  621. }
  622. /* Examine the different types of expected sub-packages */
  623. data->parent_package = sub_package;
  624. switch (package->ret_info.type) {
  625. case ACPI_PTYPE2:
  626. case ACPI_PTYPE2_PKG_COUNT:
  627. case ACPI_PTYPE2_REV_FIXED:
  628. /* Each subpackage has a fixed number of elements */
  629. expected_count =
  630. package->ret_info.count1 + package->ret_info.count2;
  631. if (sub_package->package.count < expected_count) {
  632. goto package_too_small;
  633. }
  634. status =
  635. acpi_ns_check_package_elements(data, sub_elements,
  636. package->ret_info.
  637. object_type1,
  638. package->ret_info.
  639. count1,
  640. package->ret_info.
  641. object_type2,
  642. package->ret_info.
  643. count2, 0);
  644. if (ACPI_FAILURE(status)) {
  645. return (status);
  646. }
  647. break;
  648. case ACPI_PTYPE2_FIX_VAR:
  649. /*
  650. * Each subpackage has a fixed number of elements and an
  651. * optional element
  652. */
  653. expected_count =
  654. package->ret_info.count1 + package->ret_info.count2;
  655. if (sub_package->package.count < expected_count) {
  656. goto package_too_small;
  657. }
  658. status =
  659. acpi_ns_check_package_elements(data, sub_elements,
  660. package->ret_info.
  661. object_type1,
  662. package->ret_info.
  663. count1,
  664. package->ret_info.
  665. object_type2,
  666. sub_package->package.
  667. count -
  668. package->ret_info.
  669. count1, 0);
  670. if (ACPI_FAILURE(status)) {
  671. return (status);
  672. }
  673. break;
  674. case ACPI_PTYPE2_FIXED:
  675. /* Each sub-package has a fixed length */
  676. expected_count = package->ret_info2.count;
  677. if (sub_package->package.count < expected_count) {
  678. goto package_too_small;
  679. }
  680. /* Check the type of each sub-package element */
  681. for (j = 0; j < expected_count; j++) {
  682. status =
  683. acpi_ns_check_object_type(data,
  684. &sub_elements[j],
  685. package->
  686. ret_info2.
  687. object_type[j],
  688. j);
  689. if (ACPI_FAILURE(status)) {
  690. return (status);
  691. }
  692. }
  693. break;
  694. case ACPI_PTYPE2_MIN:
  695. /* Each sub-package has a variable but minimum length */
  696. expected_count = package->ret_info.count1;
  697. if (sub_package->package.count < expected_count) {
  698. goto package_too_small;
  699. }
  700. /* Check the type of each sub-package element */
  701. status =
  702. acpi_ns_check_package_elements(data, sub_elements,
  703. package->ret_info.
  704. object_type1,
  705. sub_package->package.
  706. count, 0, 0, 0);
  707. if (ACPI_FAILURE(status)) {
  708. return (status);
  709. }
  710. break;
  711. case ACPI_PTYPE2_COUNT:
  712. /*
  713. * First element is the (Integer) count of elements, including
  714. * the count field (the ACPI name is num_elements)
  715. */
  716. status = acpi_ns_check_object_type(data, sub_elements,
  717. ACPI_RTYPE_INTEGER,
  718. 0);
  719. if (ACPI_FAILURE(status)) {
  720. return (status);
  721. }
  722. /*
  723. * Make sure package is large enough for the Count and is
  724. * is as large as the minimum size
  725. */
  726. expected_count = (u32)(*sub_elements)->integer.value;
  727. if (sub_package->package.count < expected_count) {
  728. goto package_too_small;
  729. }
  730. if (sub_package->package.count <
  731. package->ret_info.count1) {
  732. expected_count = package->ret_info.count1;
  733. goto package_too_small;
  734. }
  735. if (expected_count == 0) {
  736. /*
  737. * Either the num_entries element was originally zero or it was
  738. * a NULL element and repaired to an Integer of value zero.
  739. * In either case, repair it by setting num_entries to be the
  740. * actual size of the subpackage.
  741. */
  742. expected_count = sub_package->package.count;
  743. (*sub_elements)->integer.value = expected_count;
  744. }
  745. /* Check the type of each sub-package element */
  746. status =
  747. acpi_ns_check_package_elements(data,
  748. (sub_elements + 1),
  749. package->ret_info.
  750. object_type1,
  751. (expected_count - 1),
  752. 0, 0, 1);
  753. if (ACPI_FAILURE(status)) {
  754. return (status);
  755. }
  756. break;
  757. default: /* Should not get here, type was validated by caller */
  758. return (AE_AML_INTERNAL);
  759. }
  760. elements++;
  761. }
  762. return (AE_OK);
  763. package_too_small:
  764. /* The sub-package count was smaller than required */
  765. ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
  766. "Return Sub-Package[%u] is too small - found %u elements, expected %u",
  767. i, sub_package->package.count, expected_count));
  768. return (AE_AML_OPERAND_VALUE);
  769. }
  770. /*******************************************************************************
  771. *
  772. * FUNCTION: acpi_ns_check_package_elements
  773. *
  774. * PARAMETERS: data - Pointer to validation data structure
  775. * elements - Pointer to the package elements array
  776. * type1 - Object type for first group
  777. * count1 - Count for first group
  778. * type2 - Object type for second group
  779. * count2 - Count for second group
  780. * start_index - Start of the first group of elements
  781. *
  782. * RETURN: Status
  783. *
  784. * DESCRIPTION: Check that all elements of a package are of the correct object
  785. * type. Supports up to two groups of different object types.
  786. *
  787. ******************************************************************************/
  788. static acpi_status
  789. acpi_ns_check_package_elements(struct acpi_predefined_data *data,
  790. union acpi_operand_object **elements,
  791. u8 type1,
  792. u32 count1,
  793. u8 type2, u32 count2, u32 start_index)
  794. {
  795. union acpi_operand_object **this_element = elements;
  796. acpi_status status;
  797. u32 i;
  798. /*
  799. * Up to two groups of package elements are supported by the data
  800. * structure. All elements in each group must be of the same type.
  801. * The second group can have a count of zero.
  802. */
  803. for (i = 0; i < count1; i++) {
  804. status = acpi_ns_check_object_type(data, this_element,
  805. type1, i + start_index);
  806. if (ACPI_FAILURE(status)) {
  807. return (status);
  808. }
  809. this_element++;
  810. }
  811. for (i = 0; i < count2; i++) {
  812. status = acpi_ns_check_object_type(data, this_element,
  813. type2,
  814. (i + count1 + start_index));
  815. if (ACPI_FAILURE(status)) {
  816. return (status);
  817. }
  818. this_element++;
  819. }
  820. return (AE_OK);
  821. }
  822. /*******************************************************************************
  823. *
  824. * FUNCTION: acpi_ns_check_object_type
  825. *
  826. * PARAMETERS: data - Pointer to validation data structure
  827. * return_object_ptr - Pointer to the object returned from the
  828. * evaluation of a method or object
  829. * expected_btypes - Bitmap of expected return type(s)
  830. * package_index - Index of object within parent package (if
  831. * applicable - ACPI_NOT_PACKAGE_ELEMENT
  832. * otherwise)
  833. *
  834. * RETURN: Status
  835. *
  836. * DESCRIPTION: Check the type of the return object against the expected object
  837. * type(s). Use of Btype allows multiple expected object types.
  838. *
  839. ******************************************************************************/
  840. static acpi_status
  841. acpi_ns_check_object_type(struct acpi_predefined_data *data,
  842. union acpi_operand_object **return_object_ptr,
  843. u32 expected_btypes, u32 package_index)
  844. {
  845. union acpi_operand_object *return_object = *return_object_ptr;
  846. acpi_status status = AE_OK;
  847. u32 return_btype;
  848. char type_buffer[48]; /* Room for 5 types */
  849. /*
  850. * If we get a NULL return_object here, it is a NULL package element.
  851. * Since all extraneous NULL package elements were removed earlier by a
  852. * call to acpi_ns_remove_null_elements, this is an unexpected NULL element.
  853. * We will attempt to repair it.
  854. */
  855. if (!return_object) {
  856. status = acpi_ns_repair_null_element(data, expected_btypes,
  857. package_index,
  858. return_object_ptr);
  859. if (ACPI_SUCCESS(status)) {
  860. return (AE_OK); /* Repair was successful */
  861. }
  862. goto type_error_exit;
  863. }
  864. /* A Namespace node should not get here, but make sure */
  865. if (ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
  866. ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
  867. "Invalid return type - Found a Namespace node [%4.4s] type %s",
  868. return_object->node.name.ascii,
  869. acpi_ut_get_type_name(return_object->node.
  870. type)));
  871. return (AE_AML_OPERAND_TYPE);
  872. }
  873. /*
  874. * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
  875. * The bitmapped type allows multiple possible return types.
  876. *
  877. * Note, the cases below must handle all of the possible types returned
  878. * from all of the predefined names (including elements of returned
  879. * packages)
  880. */
  881. switch (return_object->common.type) {
  882. case ACPI_TYPE_INTEGER:
  883. return_btype = ACPI_RTYPE_INTEGER;
  884. break;
  885. case ACPI_TYPE_BUFFER:
  886. return_btype = ACPI_RTYPE_BUFFER;
  887. break;
  888. case ACPI_TYPE_STRING:
  889. return_btype = ACPI_RTYPE_STRING;
  890. break;
  891. case ACPI_TYPE_PACKAGE:
  892. return_btype = ACPI_RTYPE_PACKAGE;
  893. break;
  894. case ACPI_TYPE_LOCAL_REFERENCE:
  895. return_btype = ACPI_RTYPE_REFERENCE;
  896. break;
  897. default:
  898. /* Not one of the supported objects, must be incorrect */
  899. goto type_error_exit;
  900. }
  901. /* Is the object one of the expected types? */
  902. if (return_btype & expected_btypes) {
  903. /* For reference objects, check that the reference type is correct */
  904. if (return_object->common.type == ACPI_TYPE_LOCAL_REFERENCE) {
  905. status = acpi_ns_check_reference(data, return_object);
  906. }
  907. return (status);
  908. }
  909. /* Type mismatch -- attempt repair of the returned object */
  910. status = acpi_ns_repair_object(data, expected_btypes,
  911. package_index, return_object_ptr);
  912. if (ACPI_SUCCESS(status)) {
  913. return (AE_OK); /* Repair was successful */
  914. }
  915. type_error_exit:
  916. /* Create a string with all expected types for this predefined object */
  917. acpi_ns_get_expected_types(type_buffer, expected_btypes);
  918. if (package_index == ACPI_NOT_PACKAGE_ELEMENT) {
  919. ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
  920. "Return type mismatch - found %s, expected %s",
  921. acpi_ut_get_object_type_name
  922. (return_object), type_buffer));
  923. } else {
  924. ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
  925. "Return Package type mismatch at index %u - "
  926. "found %s, expected %s", package_index,
  927. acpi_ut_get_object_type_name
  928. (return_object), type_buffer));
  929. }
  930. return (AE_AML_OPERAND_TYPE);
  931. }
  932. /*******************************************************************************
  933. *
  934. * FUNCTION: acpi_ns_check_reference
  935. *
  936. * PARAMETERS: data - Pointer to validation data structure
  937. * return_object - Object returned from the evaluation of a
  938. * method or object
  939. *
  940. * RETURN: Status
  941. *
  942. * DESCRIPTION: Check a returned reference object for the correct reference
  943. * type. The only reference type that can be returned from a
  944. * predefined method is a named reference. All others are invalid.
  945. *
  946. ******************************************************************************/
  947. static acpi_status
  948. acpi_ns_check_reference(struct acpi_predefined_data *data,
  949. union acpi_operand_object *return_object)
  950. {
  951. /*
  952. * Check the reference object for the correct reference type (opcode).
  953. * The only type of reference that can be converted to an union acpi_object is
  954. * a reference to a named object (reference class: NAME)
  955. */
  956. if (return_object->reference.class == ACPI_REFCLASS_NAME) {
  957. return (AE_OK);
  958. }
  959. ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
  960. "Return type mismatch - unexpected reference object type [%s] %2.2X",
  961. acpi_ut_get_reference_name(return_object),
  962. return_object->reference.class));
  963. return (AE_AML_OPERAND_TYPE);
  964. }
  965. /*******************************************************************************
  966. *
  967. * FUNCTION: acpi_ns_get_expected_types
  968. *
  969. * PARAMETERS: buffer - Pointer to where the string is returned
  970. * expected_btypes - Bitmap of expected return type(s)
  971. *
  972. * RETURN: Buffer is populated with type names.
  973. *
  974. * DESCRIPTION: Translate the expected types bitmap into a string of ascii
  975. * names of expected types, for use in warning messages.
  976. *
  977. ******************************************************************************/
  978. static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes)
  979. {
  980. u32 this_rtype;
  981. u32 i;
  982. u32 j;
  983. j = 1;
  984. buffer[0] = 0;
  985. this_rtype = ACPI_RTYPE_INTEGER;
  986. for (i = 0; i < ACPI_NUM_RTYPES; i++) {
  987. /* If one of the expected types, concatenate the name of this type */
  988. if (expected_btypes & this_rtype) {
  989. ACPI_STRCAT(buffer, &acpi_rtype_names[i][j]);
  990. j = 0; /* Use name separator from now on */
  991. }
  992. this_rtype <<= 1; /* Next Rtype */
  993. }
  994. }