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