aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/acpica/nspredef.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/acpica/nspredef.c')
-rw-r--r--drivers/acpi/acpica/nspredef.c718
1 files changed, 368 insertions, 350 deletions
diff --git a/drivers/acpi/acpica/nspredef.c b/drivers/acpi/acpica/nspredef.c
index 7f8e066b12a..f8427afeebd 100644
--- a/drivers/acpi/acpica/nspredef.c
+++ b/drivers/acpi/acpica/nspredef.c
@@ -42,6 +42,8 @@
42 * POSSIBILITY OF SUCH DAMAGES. 42 * POSSIBILITY OF SUCH DAMAGES.
43 */ 43 */
44 44
45#define ACPI_CREATE_PREDEFINED_TABLE
46
45#include <acpi/acpi.h> 47#include <acpi/acpi.h>
46#include "accommon.h" 48#include "accommon.h"
47#include "acnamesp.h" 49#include "acnamesp.h"
@@ -72,30 +74,31 @@ ACPI_MODULE_NAME("nspredef")
72 ******************************************************************************/ 74 ******************************************************************************/
73/* Local prototypes */ 75/* Local prototypes */
74static acpi_status 76static acpi_status
75acpi_ns_check_package(char *pathname, 77acpi_ns_check_package(struct acpi_predefined_data *data,
76 union acpi_operand_object **return_object_ptr, 78 union acpi_operand_object **return_object_ptr);
77 const union acpi_predefined_info *predefined); 79
80static acpi_status
81acpi_ns_check_package_list(struct acpi_predefined_data *data,
82 const union acpi_predefined_info *package,
83 union acpi_operand_object **elements, u32 count);
78 84
79static acpi_status 85static acpi_status
80acpi_ns_check_package_elements(char *pathname, 86acpi_ns_check_package_elements(struct acpi_predefined_data *data,
81 union acpi_operand_object **elements, 87 union acpi_operand_object **elements,
82 u8 type1, 88 u8 type1,
83 u32 count1, 89 u32 count1,
84 u8 type2, u32 count2, u32 start_index); 90 u8 type2, u32 count2, u32 start_index);
85 91
86static acpi_status 92static acpi_status
87acpi_ns_check_object_type(char *pathname, 93acpi_ns_check_object_type(struct acpi_predefined_data *data,
88 union acpi_operand_object **return_object_ptr, 94 union acpi_operand_object **return_object_ptr,
89 u32 expected_btypes, u32 package_index); 95 u32 expected_btypes, u32 package_index);
90 96
91static acpi_status 97static acpi_status
92acpi_ns_check_reference(char *pathname, 98acpi_ns_check_reference(struct acpi_predefined_data *data,
93 union acpi_operand_object *return_object); 99 union acpi_operand_object *return_object);
94 100
95static acpi_status 101static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes);
96acpi_ns_repair_object(u32 expected_btypes,
97 u32 package_index,
98 union acpi_operand_object **return_object_ptr);
99 102
100/* 103/*
101 * Names for the types that can be returned by the predefined objects. 104 * Names for the types that can be returned by the predefined objects.
@@ -109,13 +112,13 @@ static const char *acpi_rtype_names[] = {
109 "/Reference", 112 "/Reference",
110}; 113};
111 114
112#define ACPI_NOT_PACKAGE ACPI_UINT32_MAX
113
114/******************************************************************************* 115/*******************************************************************************
115 * 116 *
116 * FUNCTION: acpi_ns_check_predefined_names 117 * FUNCTION: acpi_ns_check_predefined_names
117 * 118 *
118 * PARAMETERS: Node - Namespace node for the method/object 119 * PARAMETERS: Node - Namespace node for the method/object
120 * user_param_count - Number of parameters actually passed
121 * return_status - Status from the object evaluation
119 * return_object_ptr - Pointer to the object returned from the 122 * return_object_ptr - Pointer to the object returned from the
120 * evaluation of a method or object 123 * evaluation of a method or object
121 * 124 *
@@ -135,12 +138,13 @@ acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
135 acpi_status status = AE_OK; 138 acpi_status status = AE_OK;
136 const union acpi_predefined_info *predefined; 139 const union acpi_predefined_info *predefined;
137 char *pathname; 140 char *pathname;
141 struct acpi_predefined_data *data;
138 142
139 /* Match the name for this method/object against the predefined list */ 143 /* Match the name for this method/object against the predefined list */
140 144
141 predefined = acpi_ns_check_for_predefined_name(node); 145 predefined = acpi_ns_check_for_predefined_name(node);
142 146
143 /* Get the full pathname to the object, for use in error messages */ 147 /* Get the full pathname to the object, for use in warning messages */
144 148
145 pathname = acpi_ns_get_external_pathname(node); 149 pathname = acpi_ns_get_external_pathname(node);
146 if (!pathname) { 150 if (!pathname) {
@@ -158,28 +162,17 @@ acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
158 /* If not a predefined name, we cannot validate the return object */ 162 /* If not a predefined name, we cannot validate the return object */
159 163
160 if (!predefined) { 164 if (!predefined) {
161 goto exit; 165 goto cleanup;
162 }
163
164 /* If the method failed, we cannot validate the return object */
165
166 if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) {
167 goto exit;
168 } 166 }
169 167
170 /* 168 /*
171 * Only validate the return value on the first successful evaluation of 169 * If the method failed or did not actually return an object, we cannot
172 * the method. This ensures that any warnings will only be emitted during 170 * validate the return object
173 * the very first evaluation of the method/object.
174 */ 171 */
175 if (node->flags & ANOBJ_EVALUATED) { 172 if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) {
176 goto exit; 173 goto cleanup;
177 } 174 }
178 175
179 /* Mark the node as having been successfully evaluated */
180
181 node->flags |= ANOBJ_EVALUATED;
182
183 /* 176 /*
184 * If there is no return value, check if we require a return value for 177 * If there is no return value, check if we require a return value for
185 * this predefined name. Either one return value is expected, or none, 178 * this predefined name. Either one return value is expected, or none,
@@ -190,46 +183,67 @@ acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
190 if (!return_object) { 183 if (!return_object) {
191 if ((predefined->info.expected_btypes) && 184 if ((predefined->info.expected_btypes) &&
192 (!(predefined->info.expected_btypes & ACPI_RTYPE_NONE))) { 185 (!(predefined->info.expected_btypes & ACPI_RTYPE_NONE))) {
193 ACPI_ERROR((AE_INFO, 186 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
194 "%s: Missing expected return value", 187 ACPI_WARN_ALWAYS,
195 pathname)); 188 "Missing expected return value"));
196 189
197 status = AE_AML_NO_RETURN_VALUE; 190 status = AE_AML_NO_RETURN_VALUE;
198 } 191 }
199 goto exit; 192 goto cleanup;
200 } 193 }
201 194
202 /* 195 /*
203 * We have a return value, but if one wasn't expected, just exit, this is 196 * 1) We have a return value, but if one wasn't expected, just exit, this is
204 * not a problem 197 * not a problem. For example, if the "Implicit Return" feature is
198 * enabled, methods will always return a value.
205 * 199 *
206 * For example, if the "Implicit Return" feature is enabled, methods will 200 * 2) If the return value can be of any type, then we cannot perform any
207 * always return a value 201 * validation, exit.
208 */ 202 */
209 if (!predefined->info.expected_btypes) { 203 if ((!predefined->info.expected_btypes) ||
210 goto exit; 204 (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) {
205 goto cleanup;
211 } 206 }
212 207
208 /* Create the parameter data block for object validation */
209
210 data = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_predefined_data));
211 if (!data) {
212 goto cleanup;
213 }
214 data->predefined = predefined;
215 data->node_flags = node->flags;
216 data->pathname = pathname;
217
213 /* 218 /*
214 * Check that the type of the return object is what is expected for 219 * Check that the type of the return object is what is expected for
215 * this predefined name 220 * this predefined name
216 */ 221 */
217 status = acpi_ns_check_object_type(pathname, return_object_ptr, 222 status = acpi_ns_check_object_type(data, return_object_ptr,
218 predefined->info.expected_btypes, 223 predefined->info.expected_btypes,
219 ACPI_NOT_PACKAGE); 224 ACPI_NOT_PACKAGE_ELEMENT);
220 if (ACPI_FAILURE(status)) { 225 if (ACPI_FAILURE(status)) {
221 goto exit; 226 goto check_validation_status;
222 } 227 }
223 228
224 /* For returned Package objects, check the type of all sub-objects */ 229 /* For returned Package objects, check the type of all sub-objects */
225 230
226 if (return_object->common.type == ACPI_TYPE_PACKAGE) { 231 if (return_object->common.type == ACPI_TYPE_PACKAGE) {
227 status = 232 status = acpi_ns_check_package(data, return_object_ptr);
228 acpi_ns_check_package(pathname, return_object_ptr, 233 }
229 predefined); 234
235check_validation_status:
236 /*
237 * If the object validation failed or if we successfully repaired one
238 * or more objects, mark the parent node to suppress further warning
239 * messages during the next evaluation of the same method/object.
240 */
241 if (ACPI_FAILURE(status) || (data->flags & ACPI_OBJECT_REPAIRED)) {
242 node->flags |= ANOBJ_EVALUATED;
230 } 243 }
244 ACPI_FREE(data);
231 245
232 exit: 246cleanup:
233 ACPI_FREE(pathname); 247 ACPI_FREE(pathname);
234 return (status); 248 return (status);
235} 249}
@@ -268,64 +282,58 @@ acpi_ns_check_parameter_count(char *pathname,
268 param_count = node->object->method.param_count; 282 param_count = node->object->method.param_count;
269 } 283 }
270 284
271 /* Argument count check for non-predefined methods/objects */
272
273 if (!predefined) { 285 if (!predefined) {
274 /* 286 /*
287 * Check the parameter count for non-predefined methods/objects.
288 *
275 * Warning if too few or too many arguments have been passed by the 289 * 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 290 * caller. An incorrect number of arguments may not cause the method
277 * to fail. However, the method will fail if there are too few 291 * 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. 292 * arguments and the method attempts to use one of the missing ones.
279 */ 293 */
280 if (user_param_count < param_count) { 294 if (user_param_count < param_count) {
281 ACPI_WARNING((AE_INFO, 295 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
282 "%s: Insufficient arguments - needs %d, found %d", 296 ACPI_WARN_ALWAYS,
283 pathname, param_count, user_param_count)); 297 "Insufficient arguments - needs %u, found %u",
298 param_count, user_param_count));
284 } else if (user_param_count > param_count) { 299 } else if (user_param_count > param_count) {
285 ACPI_WARNING((AE_INFO, 300 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
286 "%s: Excess arguments - needs %d, found %d", 301 ACPI_WARN_ALWAYS,
287 pathname, param_count, user_param_count)); 302 "Excess arguments - needs %u, found %u",
303 param_count, user_param_count));
288 } 304 }
289 return; 305 return;
290 } 306 }
291 307
292 /* Allow two different legal argument counts (_SCP, etc.) */ 308 /*
293 309 * Validate the user-supplied parameter count.
310 * Allow two different legal argument counts (_SCP, etc.)
311 */
294 required_params_current = predefined->info.param_count & 0x0F; 312 required_params_current = predefined->info.param_count & 0x0F;
295 required_params_old = predefined->info.param_count >> 4; 313 required_params_old = predefined->info.param_count >> 4;
296 314
297 if (user_param_count != ACPI_UINT32_MAX) { 315 if (user_param_count != ACPI_UINT32_MAX) {
298
299 /* Validate the user-supplied parameter count */
300
301 if ((user_param_count != required_params_current) && 316 if ((user_param_count != required_params_current) &&
302 (user_param_count != required_params_old)) { 317 (user_param_count != required_params_old)) {
303 ACPI_WARNING((AE_INFO, 318 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
304 "%s: Parameter count mismatch - " 319 ACPI_WARN_ALWAYS,
305 "caller passed %d, ACPI requires %d", 320 "Parameter count mismatch - "
306 pathname, user_param_count, 321 "caller passed %u, ACPI requires %u",
307 required_params_current)); 322 user_param_count,
323 required_params_current));
308 } 324 }
309 } 325 }
310 326
311 /* 327 /*
312 * Only validate the argument count on the first successful evaluation of
313 * the method. This ensures that any warnings will only be emitted during
314 * the very first evaluation of the method/object.
315 */
316 if (node->flags & ANOBJ_EVALUATED) {
317 return;
318 }
319
320 /*
321 * Check that the ASL-defined parameter count is what is expected for 328 * Check that the ASL-defined parameter count is what is expected for
322 * this predefined name. 329 * this predefined name (parameter count as defined by the ACPI
330 * specification)
323 */ 331 */
324 if ((param_count != required_params_current) && 332 if ((param_count != required_params_current) &&
325 (param_count != required_params_old)) { 333 (param_count != required_params_old)) {
326 ACPI_WARNING((AE_INFO, 334 ACPI_WARN_PREDEFINED((AE_INFO, pathname, node->flags,
327 "%s: Parameter count mismatch - ASL declared %d, ACPI requires %d", 335 "Parameter count mismatch - ASL declared %u, ACPI requires %u",
328 pathname, param_count, required_params_current)); 336 param_count, required_params_current));
329 } 337 }
330} 338}
331 339
@@ -358,9 +366,6 @@ const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct
358 this_name = predefined_names; 366 this_name = predefined_names;
359 while (this_name->info.name[0]) { 367 while (this_name->info.name[0]) {
360 if (ACPI_COMPARE_NAME(node->name.ascii, this_name->info.name)) { 368 if (ACPI_COMPARE_NAME(node->name.ascii, this_name->info.name)) {
361
362 /* Return pointer to this table entry */
363
364 return (this_name); 369 return (this_name);
365 } 370 }
366 371
@@ -375,17 +380,16 @@ const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct
375 this_name++; 380 this_name++;
376 } 381 }
377 382
378 return (NULL); 383 return (NULL); /* Not found */
379} 384}
380 385
381/******************************************************************************* 386/*******************************************************************************
382 * 387 *
383 * FUNCTION: acpi_ns_check_package 388 * FUNCTION: acpi_ns_check_package
384 * 389 *
385 * PARAMETERS: Pathname - Full pathname to the node (for error msgs) 390 * PARAMETERS: Data - Pointer to validation data structure
386 * return_object_ptr - Pointer to the object returned from the 391 * return_object_ptr - Pointer to the object returned from the
387 * evaluation of a method or object 392 * evaluation of a method or object
388 * Predefined - Pointer to entry in predefined name table
389 * 393 *
390 * RETURN: Status 394 * RETURN: Status
391 * 395 *
@@ -395,30 +399,26 @@ const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct
395 ******************************************************************************/ 399 ******************************************************************************/
396 400
397static acpi_status 401static acpi_status
398acpi_ns_check_package(char *pathname, 402acpi_ns_check_package(struct acpi_predefined_data *data,
399 union acpi_operand_object **return_object_ptr, 403 union acpi_operand_object **return_object_ptr)
400 const union acpi_predefined_info *predefined)
401{ 404{
402 union acpi_operand_object *return_object = *return_object_ptr; 405 union acpi_operand_object *return_object = *return_object_ptr;
403 const union acpi_predefined_info *package; 406 const union acpi_predefined_info *package;
404 union acpi_operand_object *sub_package;
405 union acpi_operand_object **elements; 407 union acpi_operand_object **elements;
406 union acpi_operand_object **sub_elements; 408 acpi_status status = AE_OK;
407 acpi_status status;
408 u32 expected_count; 409 u32 expected_count;
409 u32 count; 410 u32 count;
410 u32 i; 411 u32 i;
411 u32 j;
412 412
413 ACPI_FUNCTION_NAME(ns_check_package); 413 ACPI_FUNCTION_NAME(ns_check_package);
414 414
415 /* The package info for this name is in the next table entry */ 415 /* The package info for this name is in the next table entry */
416 416
417 package = predefined + 1; 417 package = data->predefined + 1;
418 418
419 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, 419 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
420 "%s Validating return Package of Type %X, Count %X\n", 420 "%s Validating return Package of Type %X, Count %X\n",
421 pathname, package->ret_info.type, 421 data->pathname, package->ret_info.type,
422 return_object->package.count)); 422 return_object->package.count));
423 423
424 /* Extract package count and elements array */ 424 /* Extract package count and elements array */
@@ -429,9 +429,8 @@ acpi_ns_check_package(char *pathname,
429 /* The package must have at least one element, else invalid */ 429 /* The package must have at least one element, else invalid */
430 430
431 if (!count) { 431 if (!count) {
432 ACPI_WARNING((AE_INFO, 432 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
433 "%s: Return Package has no elements (empty)", 433 "Return Package has no elements (empty)"));
434 pathname));
435 434
436 return (AE_AML_OPERAND_VALUE); 435 return (AE_AML_OPERAND_VALUE);
437 } 436 }
@@ -456,15 +455,16 @@ acpi_ns_check_package(char *pathname,
456 if (count < expected_count) { 455 if (count < expected_count) {
457 goto package_too_small; 456 goto package_too_small;
458 } else if (count > expected_count) { 457 } else if (count > expected_count) {
459 ACPI_WARNING((AE_INFO, 458 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
460 "%s: Return Package is larger than needed - " 459 data->node_flags,
461 "found %u, expected %u", pathname, count, 460 "Return Package is larger than needed - "
462 expected_count)); 461 "found %u, expected %u", count,
462 expected_count));
463 } 463 }
464 464
465 /* Validate all elements of the returned package */ 465 /* Validate all elements of the returned package */
466 466
467 status = acpi_ns_check_package_elements(pathname, elements, 467 status = acpi_ns_check_package_elements(data, elements,
468 package->ret_info. 468 package->ret_info.
469 object_type1, 469 object_type1,
470 package->ret_info. 470 package->ret_info.
@@ -473,9 +473,6 @@ acpi_ns_check_package(char *pathname,
473 object_type2, 473 object_type2,
474 package->ret_info. 474 package->ret_info.
475 count2, 0); 475 count2, 0);
476 if (ACPI_FAILURE(status)) {
477 return (status);
478 }
479 break; 476 break;
480 477
481 case ACPI_PTYPE1_VAR: 478 case ACPI_PTYPE1_VAR:
@@ -485,7 +482,7 @@ acpi_ns_check_package(char *pathname,
485 * elements must be of the same type 482 * elements must be of the same type
486 */ 483 */
487 for (i = 0; i < count; i++) { 484 for (i = 0; i < count; i++) {
488 status = acpi_ns_check_object_type(pathname, elements, 485 status = acpi_ns_check_object_type(data, elements,
489 package->ret_info. 486 package->ret_info.
490 object_type1, i); 487 object_type1, i);
491 if (ACPI_FAILURE(status)) { 488 if (ACPI_FAILURE(status)) {
@@ -517,8 +514,7 @@ acpi_ns_check_package(char *pathname,
517 /* These are the required package elements (0, 1, or 2) */ 514 /* These are the required package elements (0, 1, or 2) */
518 515
519 status = 516 status =
520 acpi_ns_check_object_type(pathname, 517 acpi_ns_check_object_type(data, elements,
521 elements,
522 package-> 518 package->
523 ret_info3. 519 ret_info3.
524 object_type[i], 520 object_type[i],
@@ -530,8 +526,7 @@ acpi_ns_check_package(char *pathname,
530 /* These are the optional package elements */ 526 /* These are the optional package elements */
531 527
532 status = 528 status =
533 acpi_ns_check_object_type(pathname, 529 acpi_ns_check_object_type(data, elements,
534 elements,
535 package-> 530 package->
536 ret_info3. 531 ret_info3.
537 tail_object_type, 532 tail_object_type,
@@ -544,11 +539,30 @@ acpi_ns_check_package(char *pathname,
544 } 539 }
545 break; 540 break;
546 541
542 case ACPI_PTYPE2_REV_FIXED:
543
544 /* First element is the (Integer) revision */
545
546 status = acpi_ns_check_object_type(data, elements,
547 ACPI_RTYPE_INTEGER, 0);
548 if (ACPI_FAILURE(status)) {
549 return (status);
550 }
551
552 elements++;
553 count--;
554
555 /* Examine the sub-packages */
556
557 status =
558 acpi_ns_check_package_list(data, package, elements, count);
559 break;
560
547 case ACPI_PTYPE2_PKG_COUNT: 561 case ACPI_PTYPE2_PKG_COUNT:
548 562
549 /* First element is the (Integer) count of sub-packages to follow */ 563 /* First element is the (Integer) count of sub-packages to follow */
550 564
551 status = acpi_ns_check_object_type(pathname, elements, 565 status = acpi_ns_check_object_type(data, elements,
552 ACPI_RTYPE_INTEGER, 0); 566 ACPI_RTYPE_INTEGER, 0);
553 if (ACPI_FAILURE(status)) { 567 if (ACPI_FAILURE(status)) {
554 return (status); 568 return (status);
@@ -566,9 +580,11 @@ acpi_ns_check_package(char *pathname,
566 count = expected_count; 580 count = expected_count;
567 elements++; 581 elements++;
568 582
569 /* Now we can walk the sub-packages */ 583 /* Examine the sub-packages */
570 584
571 /*lint -fallthrough */ 585 status =
586 acpi_ns_check_package_list(data, package, elements, count);
587 break;
572 588
573 case ACPI_PTYPE2: 589 case ACPI_PTYPE2:
574 case ACPI_PTYPE2_FIXED: 590 case ACPI_PTYPE2_FIXED:
@@ -576,176 +592,240 @@ acpi_ns_check_package(char *pathname,
576 case ACPI_PTYPE2_COUNT: 592 case ACPI_PTYPE2_COUNT:
577 593
578 /* 594 /*
579 * These types all return a single package that consists of a variable 595 * These types all return a single Package that consists of a
580 * number of sub-packages 596 * variable number of sub-Packages.
597 *
598 * First, ensure that the first element is a sub-Package. If not,
599 * the BIOS may have incorrectly returned the object as a single
600 * package instead of a Package of Packages (a common error if
601 * there is only one entry). We may be able to repair this by
602 * wrapping the returned Package with a new outer Package.
581 */ 603 */
582 for (i = 0; i < count; i++) { 604 if ((*elements)->common.type != ACPI_TYPE_PACKAGE) {
583 sub_package = *elements;
584 sub_elements = sub_package->package.elements;
585 605
586 /* Each sub-object must be of type Package */ 606 /* Create the new outer package and populate it */
587 607
588 status = 608 status =
589 acpi_ns_check_object_type(pathname, &sub_package, 609 acpi_ns_repair_package_list(data,
590 ACPI_RTYPE_PACKAGE, i); 610 return_object_ptr);
591 if (ACPI_FAILURE(status)) { 611 if (ACPI_FAILURE(status)) {
592 return (status); 612 return (status);
593 } 613 }
594 614
595 /* Examine the different types of sub-packages */ 615 /* Update locals to point to the new package (of 1 element) */
596 616
597 switch (package->ret_info.type) { 617 return_object = *return_object_ptr;
598 case ACPI_PTYPE2: 618 elements = return_object->package.elements;
599 case ACPI_PTYPE2_PKG_COUNT: 619 count = 1;
620 }
600 621
601 /* Each subpackage has a fixed number of elements */ 622 /* Examine the sub-packages */
602 623
603 expected_count = 624 status =
604 package->ret_info.count1 + 625 acpi_ns_check_package_list(data, package, elements, count);
605 package->ret_info.count2; 626 break;
606 if (sub_package->package.count !=
607 expected_count) {
608 count = sub_package->package.count;
609 goto package_too_small;
610 }
611 627
612 status = 628 default:
613 acpi_ns_check_package_elements(pathname,
614 sub_elements,
615 package->
616 ret_info.
617 object_type1,
618 package->
619 ret_info.
620 count1,
621 package->
622 ret_info.
623 object_type2,
624 package->
625 ret_info.
626 count2, 0);
627 if (ACPI_FAILURE(status)) {
628 return (status);
629 }
630 break;
631 629
632 case ACPI_PTYPE2_FIXED: 630 /* Should not get here if predefined info table is correct */
633 631
634 /* Each sub-package has a fixed length */ 632 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
633 "Invalid internal return type in table entry: %X",
634 package->ret_info.type));
635 635
636 expected_count = package->ret_info2.count; 636 return (AE_AML_INTERNAL);
637 if (sub_package->package.count < expected_count) { 637 }
638 count = sub_package->package.count;
639 goto package_too_small;
640 }
641 638
642 /* Check the type of each sub-package element */ 639 return (status);
643 640
644 for (j = 0; j < expected_count; j++) { 641package_too_small:
645 status =
646 acpi_ns_check_object_type(pathname,
647 &sub_elements[j],
648 package->ret_info2.object_type[j], j);
649 if (ACPI_FAILURE(status)) {
650 return (status);
651 }
652 }
653 break;
654 642
655 case ACPI_PTYPE2_MIN: 643 /* Error exit for the case with an incorrect package count */
656 644
657 /* Each sub-package has a variable but minimum length */ 645 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
646 "Return Package is too small - found %u elements, expected %u",
647 count, expected_count));
658 648
659 expected_count = package->ret_info.count1; 649 return (AE_AML_OPERAND_VALUE);
660 if (sub_package->package.count < expected_count) { 650}
661 count = sub_package->package.count;
662 goto package_too_small;
663 }
664 651
665 /* Check the type of each sub-package element */ 652/*******************************************************************************
653 *
654 * FUNCTION: acpi_ns_check_package_list
655 *
656 * PARAMETERS: Data - Pointer to validation data structure
657 * Package - Pointer to package-specific info for method
658 * Elements - Element list of parent package. All elements
659 * of this list should be of type Package.
660 * Count - Count of subpackages
661 *
662 * RETURN: Status
663 *
664 * DESCRIPTION: Examine a list of subpackages
665 *
666 ******************************************************************************/
666 667
667 status = 668static acpi_status
668 acpi_ns_check_package_elements(pathname, 669acpi_ns_check_package_list(struct acpi_predefined_data *data,
669 sub_elements, 670 const union acpi_predefined_info *package,
670 package-> 671 union acpi_operand_object **elements, u32 count)
671 ret_info. 672{
672 object_type1, 673 union acpi_operand_object *sub_package;
673 sub_package-> 674 union acpi_operand_object **sub_elements;
674 package. 675 acpi_status status;
675 count, 0, 0, 676 u32 expected_count;
676 0); 677 u32 i;
677 if (ACPI_FAILURE(status)) { 678 u32 j;
678 return (status);
679 }
680 break;
681 679
682 case ACPI_PTYPE2_COUNT: 680 /* Validate each sub-Package in the parent Package */
683 681
684 /* First element is the (Integer) count of elements to follow */ 682 for (i = 0; i < count; i++) {
683 sub_package = *elements;
684 sub_elements = sub_package->package.elements;
685 685
686 status = 686 /* Each sub-object must be of type Package */
687 acpi_ns_check_object_type(pathname,
688 sub_elements,
689 ACPI_RTYPE_INTEGER,
690 0);
691 if (ACPI_FAILURE(status)) {
692 return (status);
693 }
694 687
695 /* Make sure package is large enough for the Count */ 688 status = acpi_ns_check_object_type(data, &sub_package,
689 ACPI_RTYPE_PACKAGE, i);
690 if (ACPI_FAILURE(status)) {
691 return (status);
692 }
696 693
697 expected_count = 694 /* Examine the different types of expected sub-packages */
698 (u32) (*sub_elements)->integer.value; 695
699 if (sub_package->package.count < expected_count) { 696 switch (package->ret_info.type) {
700 count = sub_package->package.count; 697 case ACPI_PTYPE2:
701 goto package_too_small; 698 case ACPI_PTYPE2_PKG_COUNT:
702 } 699 case ACPI_PTYPE2_REV_FIXED:
700
701 /* Each subpackage has a fixed number of elements */
702
703 expected_count =
704 package->ret_info.count1 + package->ret_info.count2;
705 if (sub_package->package.count < expected_count) {
706 goto package_too_small;
707 }
708
709 status =
710 acpi_ns_check_package_elements(data, sub_elements,
711 package->ret_info.
712 object_type1,
713 package->ret_info.
714 count1,
715 package->ret_info.
716 object_type2,
717 package->ret_info.
718 count2, 0);
719 if (ACPI_FAILURE(status)) {
720 return (status);
721 }
722 break;
703 723
704 /* Check the type of each sub-package element */ 724 case ACPI_PTYPE2_FIXED:
705 725
726 /* Each sub-package has a fixed length */
727
728 expected_count = package->ret_info2.count;
729 if (sub_package->package.count < expected_count) {
730 goto package_too_small;
731 }
732
733 /* Check the type of each sub-package element */
734
735 for (j = 0; j < expected_count; j++) {
706 status = 736 status =
707 acpi_ns_check_package_elements(pathname, 737 acpi_ns_check_object_type(data,
708 (sub_elements 738 &sub_elements[j],
709 + 1), 739 package->
710 package-> 740 ret_info2.
711 ret_info. 741 object_type[j],
712 object_type1, 742 j);
713 (expected_count
714 - 1), 0, 0,
715 1);
716 if (ACPI_FAILURE(status)) { 743 if (ACPI_FAILURE(status)) {
717 return (status); 744 return (status);
718 } 745 }
719 break; 746 }
747 break;
748
749 case ACPI_PTYPE2_MIN:
720 750
721 default: 751 /* Each sub-package has a variable but minimum length */
722 break; 752
753 expected_count = package->ret_info.count1;
754 if (sub_package->package.count < expected_count) {
755 goto package_too_small;
723 } 756 }
724 757
725 elements++; 758 /* Check the type of each sub-package element */
726 }
727 break;
728 759
729 default: 760 status =
761 acpi_ns_check_package_elements(data, sub_elements,
762 package->ret_info.
763 object_type1,
764 sub_package->package.
765 count, 0, 0, 0);
766 if (ACPI_FAILURE(status)) {
767 return (status);
768 }
769 break;
730 770
731 /* Should not get here if predefined info table is correct */ 771 case ACPI_PTYPE2_COUNT:
772
773 /*
774 * First element is the (Integer) count of elements, including
775 * the count field.
776 */
777 status = acpi_ns_check_object_type(data, sub_elements,
778 ACPI_RTYPE_INTEGER,
779 0);
780 if (ACPI_FAILURE(status)) {
781 return (status);
782 }
732 783
733 ACPI_WARNING((AE_INFO, 784 /*
734 "%s: Invalid internal return type in table entry: %X", 785 * Make sure package is large enough for the Count and is
735 pathname, package->ret_info.type)); 786 * is as large as the minimum size
787 */
788 expected_count = (u32)(*sub_elements)->integer.value;
789 if (sub_package->package.count < expected_count) {
790 goto package_too_small;
791 }
792 if (sub_package->package.count <
793 package->ret_info.count1) {
794 expected_count = package->ret_info.count1;
795 goto package_too_small;
796 }
736 797
737 return (AE_AML_INTERNAL); 798 /* Check the type of each sub-package element */
799
800 status =
801 acpi_ns_check_package_elements(data,
802 (sub_elements + 1),
803 package->ret_info.
804 object_type1,
805 (expected_count - 1),
806 0, 0, 1);
807 if (ACPI_FAILURE(status)) {
808 return (status);
809 }
810 break;
811
812 default: /* Should not get here, type was validated by caller */
813
814 return (AE_AML_INTERNAL);
815 }
816
817 elements++;
738 } 818 }
739 819
740 return (AE_OK); 820 return (AE_OK);
741 821
742 package_too_small: 822package_too_small:
743 823
744 /* Error exit for the case with an incorrect package count */ 824 /* The sub-package count was smaller than required */
745 825
746 ACPI_WARNING((AE_INFO, "%s: Return Package is too small - " 826 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
747 "found %u, expected %u", pathname, count, 827 "Return Sub-Package[%u] is too small - found %u elements, expected %u",
748 expected_count)); 828 i, sub_package->package.count, expected_count));
749 829
750 return (AE_AML_OPERAND_VALUE); 830 return (AE_AML_OPERAND_VALUE);
751} 831}
@@ -754,7 +834,7 @@ acpi_ns_check_package(char *pathname,
754 * 834 *
755 * FUNCTION: acpi_ns_check_package_elements 835 * FUNCTION: acpi_ns_check_package_elements
756 * 836 *
757 * PARAMETERS: Pathname - Full pathname to the node (for error msgs) 837 * PARAMETERS: Data - Pointer to validation data structure
758 * Elements - Pointer to the package elements array 838 * Elements - Pointer to the package elements array
759 * Type1 - Object type for first group 839 * Type1 - Object type for first group
760 * Count1 - Count for first group 840 * Count1 - Count for first group
@@ -770,7 +850,7 @@ acpi_ns_check_package(char *pathname,
770 ******************************************************************************/ 850 ******************************************************************************/
771 851
772static acpi_status 852static acpi_status
773acpi_ns_check_package_elements(char *pathname, 853acpi_ns_check_package_elements(struct acpi_predefined_data *data,
774 union acpi_operand_object **elements, 854 union acpi_operand_object **elements,
775 u8 type1, 855 u8 type1,
776 u32 count1, 856 u32 count1,
@@ -786,7 +866,7 @@ acpi_ns_check_package_elements(char *pathname,
786 * The second group can have a count of zero. 866 * The second group can have a count of zero.
787 */ 867 */
788 for (i = 0; i < count1; i++) { 868 for (i = 0; i < count1; i++) {
789 status = acpi_ns_check_object_type(pathname, this_element, 869 status = acpi_ns_check_object_type(data, this_element,
790 type1, i + start_index); 870 type1, i + start_index);
791 if (ACPI_FAILURE(status)) { 871 if (ACPI_FAILURE(status)) {
792 return (status); 872 return (status);
@@ -795,7 +875,7 @@ acpi_ns_check_package_elements(char *pathname,
795 } 875 }
796 876
797 for (i = 0; i < count2; i++) { 877 for (i = 0; i < count2; i++) {
798 status = acpi_ns_check_object_type(pathname, this_element, 878 status = acpi_ns_check_object_type(data, this_element,
799 type2, 879 type2,
800 (i + count1 + start_index)); 880 (i + count1 + start_index));
801 if (ACPI_FAILURE(status)) { 881 if (ACPI_FAILURE(status)) {
@@ -811,12 +891,13 @@ acpi_ns_check_package_elements(char *pathname,
811 * 891 *
812 * FUNCTION: acpi_ns_check_object_type 892 * FUNCTION: acpi_ns_check_object_type
813 * 893 *
814 * PARAMETERS: Pathname - Full pathname to the node (for error msgs) 894 * PARAMETERS: Data - Pointer to validation data structure
815 * return_object_ptr - Pointer to the object returned from the 895 * return_object_ptr - Pointer to the object returned from the
816 * evaluation of a method or object 896 * evaluation of a method or object
817 * expected_btypes - Bitmap of expected return type(s) 897 * expected_btypes - Bitmap of expected return type(s)
818 * package_index - Index of object within parent package (if 898 * package_index - Index of object within parent package (if
819 * applicable - ACPI_NOT_PACKAGE otherwise) 899 * applicable - ACPI_NOT_PACKAGE_ELEMENT
900 * otherwise)
820 * 901 *
821 * RETURN: Status 902 * RETURN: Status
822 * 903 *
@@ -826,7 +907,7 @@ acpi_ns_check_package_elements(char *pathname,
826 ******************************************************************************/ 907 ******************************************************************************/
827 908
828static acpi_status 909static acpi_status
829acpi_ns_check_object_type(char *pathname, 910acpi_ns_check_object_type(struct acpi_predefined_data *data,
830 union acpi_operand_object **return_object_ptr, 911 union acpi_operand_object **return_object_ptr,
831 u32 expected_btypes, u32 package_index) 912 u32 expected_btypes, u32 package_index)
832{ 913{
@@ -834,9 +915,6 @@ acpi_ns_check_object_type(char *pathname,
834 acpi_status status = AE_OK; 915 acpi_status status = AE_OK;
835 u32 return_btype; 916 u32 return_btype;
836 char type_buffer[48]; /* Room for 5 types */ 917 char type_buffer[48]; /* Room for 5 types */
837 u32 this_rtype;
838 u32 i;
839 u32 j;
840 918
841 /* 919 /*
842 * If we get a NULL return_object here, it is a NULL package element, 920 * If we get a NULL return_object here, it is a NULL package element,
@@ -849,10 +927,11 @@ acpi_ns_check_object_type(char *pathname,
849 /* A Namespace node should not get here, but make sure */ 927 /* A Namespace node should not get here, but make sure */
850 928
851 if (ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) { 929 if (ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
852 ACPI_WARNING((AE_INFO, 930 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
853 "%s: Invalid return type - Found a Namespace node [%4.4s] type %s", 931 "Invalid return type - Found a Namespace node [%4.4s] type %s",
854 pathname, return_object->node.name.ascii, 932 return_object->node.name.ascii,
855 acpi_ut_get_type_name(return_object->node.type))); 933 acpi_ut_get_type_name(return_object->node.
934 type)));
856 return (AE_AML_OPERAND_TYPE); 935 return (AE_AML_OPERAND_TYPE);
857 } 936 }
858 937
@@ -897,10 +976,11 @@ acpi_ns_check_object_type(char *pathname,
897 976
898 /* Type mismatch -- attempt repair of the returned object */ 977 /* Type mismatch -- attempt repair of the returned object */
899 978
900 status = acpi_ns_repair_object(expected_btypes, package_index, 979 status = acpi_ns_repair_object(data, expected_btypes,
980 package_index,
901 return_object_ptr); 981 return_object_ptr);
902 if (ACPI_SUCCESS(status)) { 982 if (ACPI_SUCCESS(status)) {
903 return (status); 983 return (AE_OK); /* Repair was successful */
904 } 984 }
905 goto type_error_exit; 985 goto type_error_exit;
906 } 986 }
@@ -908,7 +988,7 @@ acpi_ns_check_object_type(char *pathname,
908 /* For reference objects, check that the reference type is correct */ 988 /* For reference objects, check that the reference type is correct */
909 989
910 if (return_object->common.type == ACPI_TYPE_LOCAL_REFERENCE) { 990 if (return_object->common.type == ACPI_TYPE_LOCAL_REFERENCE) {
911 status = acpi_ns_check_reference(pathname, return_object); 991 status = acpi_ns_check_reference(data, return_object);
912 } 992 }
913 993
914 return (status); 994 return (status);
@@ -917,33 +997,19 @@ acpi_ns_check_object_type(char *pathname,
917 997
918 /* Create a string with all expected types for this predefined object */ 998 /* Create a string with all expected types for this predefined object */
919 999
920 j = 1; 1000 acpi_ns_get_expected_types(type_buffer, expected_btypes);
921 type_buffer[0] = 0;
922 this_rtype = ACPI_RTYPE_INTEGER;
923
924 for (i = 0; i < ACPI_NUM_RTYPES; i++) {
925
926 /* If one of the expected types, concatenate the name of this type */
927
928 if (expected_btypes & this_rtype) {
929 ACPI_STRCAT(type_buffer, &acpi_rtype_names[i][j]);
930 j = 0; /* Use name separator from now on */
931 }
932 this_rtype <<= 1; /* Next Rtype */
933 }
934 1001
935 if (package_index == ACPI_NOT_PACKAGE) { 1002 if (package_index == ACPI_NOT_PACKAGE_ELEMENT) {
936 ACPI_WARNING((AE_INFO, 1003 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
937 "%s: Return type mismatch - found %s, expected %s", 1004 "Return type mismatch - found %s, expected %s",
938 pathname, 1005 acpi_ut_get_object_type_name
939 acpi_ut_get_object_type_name(return_object), 1006 (return_object), type_buffer));
940 type_buffer));
941 } else { 1007 } else {
942 ACPI_WARNING((AE_INFO, 1008 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
943 "%s: Return Package type mismatch at index %u - " 1009 "Return Package type mismatch at index %u - "
944 "found %s, expected %s", pathname, package_index, 1010 "found %s, expected %s", package_index,
945 acpi_ut_get_object_type_name(return_object), 1011 acpi_ut_get_object_type_name
946 type_buffer)); 1012 (return_object), type_buffer));
947 } 1013 }
948 1014
949 return (AE_AML_OPERAND_TYPE); 1015 return (AE_AML_OPERAND_TYPE);
@@ -953,7 +1019,7 @@ acpi_ns_check_object_type(char *pathname,
953 * 1019 *
954 * FUNCTION: acpi_ns_check_reference 1020 * FUNCTION: acpi_ns_check_reference
955 * 1021 *
956 * PARAMETERS: Pathname - Full pathname to the node (for error msgs) 1022 * PARAMETERS: Data - Pointer to validation data structure
957 * return_object - Object returned from the evaluation of a 1023 * return_object - Object returned from the evaluation of a
958 * method or object 1024 * method or object
959 * 1025 *
@@ -966,7 +1032,7 @@ acpi_ns_check_object_type(char *pathname,
966 ******************************************************************************/ 1032 ******************************************************************************/
967 1033
968static acpi_status 1034static acpi_status
969acpi_ns_check_reference(char *pathname, 1035acpi_ns_check_reference(struct acpi_predefined_data *data,
970 union acpi_operand_object *return_object) 1036 union acpi_operand_object *return_object)
971{ 1037{
972 1038
@@ -979,94 +1045,46 @@ acpi_ns_check_reference(char *pathname,
979 return (AE_OK); 1045 return (AE_OK);
980 } 1046 }
981 1047
982 ACPI_WARNING((AE_INFO, 1048 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
983 "%s: Return type mismatch - " 1049 "Return type mismatch - unexpected reference object type [%s] %2.2X",
984 "unexpected reference object type [%s] %2.2X", 1050 acpi_ut_get_reference_name(return_object),
985 pathname, acpi_ut_get_reference_name(return_object), 1051 return_object->reference.class));
986 return_object->reference.class));
987 1052
988 return (AE_AML_OPERAND_TYPE); 1053 return (AE_AML_OPERAND_TYPE);
989} 1054}
990 1055
991/******************************************************************************* 1056/*******************************************************************************
992 * 1057 *
993 * FUNCTION: acpi_ns_repair_object 1058 * FUNCTION: acpi_ns_get_expected_types
994 * 1059 *
995 * PARAMETERS: Pathname - Full pathname to the node (for error msgs) 1060 * PARAMETERS: Buffer - Pointer to where the string is returned
996 * package_index - Used to determine if target is in a package 1061 * expected_btypes - Bitmap of expected return type(s)
997 * return_object_ptr - Pointer to the object returned from the
998 * evaluation of a method or object
999 * 1062 *
1000 * RETURN: Status. AE_OK if repair was successful. 1063 * RETURN: Buffer is populated with type names.
1001 * 1064 *
1002 * DESCRIPTION: Attempt to repair/convert a return object of a type that was 1065 * DESCRIPTION: Translate the expected types bitmap into a string of ascii
1003 * not expected. 1066 * names of expected types, for use in warning messages.
1004 * 1067 *
1005 ******************************************************************************/ 1068 ******************************************************************************/
1006 1069
1007static acpi_status 1070static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes)
1008acpi_ns_repair_object(u32 expected_btypes,
1009 u32 package_index,
1010 union acpi_operand_object **return_object_ptr)
1011{ 1071{
1012 union acpi_operand_object *return_object = *return_object_ptr; 1072 u32 this_rtype;
1013 union acpi_operand_object *new_object; 1073 u32 i;
1014 acpi_size length; 1074 u32 j;
1015
1016 switch (return_object->common.type) {
1017 case ACPI_TYPE_BUFFER:
1018
1019 if (!(expected_btypes & ACPI_RTYPE_STRING)) {
1020 return (AE_AML_OPERAND_TYPE);
1021 }
1022
1023 /*
1024 * Have a Buffer, expected a String, convert. Use a to_string
1025 * conversion, no transform performed on the buffer data. The best
1026 * example of this is the _BIF method, where the string data from
1027 * the battery is often (incorrectly) returned as buffer object(s).
1028 */
1029 length = 0;
1030 while ((length < return_object->buffer.length) &&
1031 (return_object->buffer.pointer[length])) {
1032 length++;
1033 }
1034
1035 /* Allocate a new string object */
1036
1037 new_object = acpi_ut_create_string_object(length);
1038 if (!new_object) {
1039 return (AE_NO_MEMORY);
1040 }
1041 1075
1042 /* 1076 j = 1;
1043 * Copy the raw buffer data with no transform. String is already NULL 1077 buffer[0] = 0;
1044 * terminated at Length+1. 1078 this_rtype = ACPI_RTYPE_INTEGER;
1045 */
1046 ACPI_MEMCPY(new_object->string.pointer,
1047 return_object->buffer.pointer, length);
1048 1079
1049 /* Install the new return object */ 1080 for (i = 0; i < ACPI_NUM_RTYPES; i++) {
1050 1081
1051 acpi_ut_remove_reference(return_object); 1082 /* If one of the expected types, concatenate the name of this type */
1052 *return_object_ptr = new_object;
1053 1083
1054 /* 1084 if (expected_btypes & this_rtype) {
1055 * If the object is a package element, we need to: 1085 ACPI_STRCAT(buffer, &acpi_rtype_names[i][j]);
1056 * 1. Decrement the reference count of the orignal object, it was 1086 j = 0; /* Use name separator from now on */
1057 * incremented when building the package
1058 * 2. Increment the reference count of the new object, it will be
1059 * decremented when releasing the package
1060 */
1061 if (package_index != ACPI_NOT_PACKAGE) {
1062 acpi_ut_remove_reference(return_object);
1063 acpi_ut_add_reference(new_object);
1064 } 1087 }
1065 return (AE_OK); 1088 this_rtype <<= 1; /* Next Rtype */
1066
1067 default:
1068 break;
1069 } 1089 }
1070
1071 return (AE_AML_OPERAND_TYPE);
1072} 1090}