f0275025b718d7c45ce10046e3cf86d75a6392df
[firefly-linux-kernel-4.4.55.git] / drivers / acpi / utilities / utmisc.c
1 /*******************************************************************************
2  *
3  * Module Name: utmisc - common utility procedures
4  *
5  ******************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2005, R. Byron Moore
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44 #include <acpi/acpi.h>
45 #include <acpi/acnamesp.h>
46
47 #define _COMPONENT          ACPI_UTILITIES
48 ACPI_MODULE_NAME("utmisc")
49
50 /*******************************************************************************
51  *
52  * FUNCTION:    acpi_ut_allocate_owner_id
53  *
54  * PARAMETERS:  owner_id        - Where the new owner ID is returned
55  *
56  * RETURN:      Status
57  *
58  * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
59  *              track objects created by the table or method, to be deleted
60  *              when the method exits or the table is unloaded.
61  *
62  ******************************************************************************/
63 acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
64 {
65         acpi_native_uint i;
66         acpi_status status;
67
68         ACPI_FUNCTION_TRACE("ut_allocate_owner_id");
69
70         /* Mutex for the global ID mask */
71
72         status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
73         if (ACPI_FAILURE(status)) {
74                 return_ACPI_STATUS(status);
75         }
76
77         /* Find a free owner ID */
78
79         for (i = 0; i < 32; i++) {
80                 if (!(acpi_gbl_owner_id_mask & (1 << i))) {
81                         ACPI_DEBUG_PRINT((ACPI_DB_VALUES,
82                                           "Current owner_id mask: %8.8X New ID: %2.2X\n",
83                                           acpi_gbl_owner_id_mask, (i + 1)));
84
85                         acpi_gbl_owner_id_mask |= (1 << i);
86                         *owner_id = (acpi_owner_id) (i + 1);
87                         goto exit;
88                 }
89         }
90
91         /*
92          * If we are here, all owner_ids have been allocated. This probably should
93          * not happen since the IDs are reused after deallocation. The IDs are
94          * allocated upon table load (one per table) and method execution, and
95          * they are released when a table is unloaded or a method completes
96          * execution.
97          */
98         *owner_id = 0;
99         status = AE_OWNER_ID_LIMIT;
100         ACPI_REPORT_ERROR(("Could not allocate new owner_id (32 max), AE_OWNER_ID_LIMIT\n"));
101
102       exit:
103         (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
104         return_ACPI_STATUS(status);
105 }
106
107 /*******************************************************************************
108  *
109  * FUNCTION:    acpi_ut_release_owner_id
110  *
111  * PARAMETERS:  owner_id_ptr        - Pointer to a previously allocated owner_iD
112  *
113  * RETURN:      None. No error is returned because we are either exiting a
114  *              control method or unloading a table. Either way, we would
115  *              ignore any error anyway.
116  *
117  * DESCRIPTION: Release a table or method owner ID.  Valid IDs are 1 - 32
118  *
119  ******************************************************************************/
120
121 void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
122 {
123         acpi_owner_id owner_id = *owner_id_ptr;
124         acpi_status status;
125
126         ACPI_FUNCTION_TRACE_U32("ut_release_owner_id", owner_id);
127
128         /* Always clear the input owner_id (zero is an invalid ID) */
129
130         *owner_id_ptr = 0;
131
132         /* Zero is not a valid owner_iD */
133
134         if ((owner_id == 0) || (owner_id > 32)) {
135                 ACPI_REPORT_ERROR(("Invalid owner_id: %2.2X\n", owner_id));
136                 return_VOID;
137         }
138
139         /* Mutex for the global ID mask */
140
141         status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
142         if (ACPI_FAILURE(status)) {
143                 return_VOID;
144         }
145
146         owner_id--;             /* Normalize to zero */
147
148         /* Free the owner ID only if it is valid */
149
150         if (acpi_gbl_owner_id_mask & (1 << owner_id)) {
151                 acpi_gbl_owner_id_mask ^= (1 << owner_id);
152         }
153
154         (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
155         return_VOID;
156 }
157
158 /*******************************************************************************
159  *
160  * FUNCTION:    acpi_ut_strupr (strupr)
161  *
162  * PARAMETERS:  src_string      - The source string to convert
163  *
164  * RETURN:      None
165  *
166  * DESCRIPTION: Convert string to uppercase
167  *
168  * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
169  *
170  ******************************************************************************/
171
172 void acpi_ut_strupr(char *src_string)
173 {
174         char *string;
175
176         ACPI_FUNCTION_ENTRY();
177
178         if (!src_string) {
179                 return;
180         }
181
182         /* Walk entire string, uppercasing the letters */
183
184         for (string = src_string; *string; string++) {
185                 *string = (char)ACPI_TOUPPER(*string);
186         }
187
188         return;
189 }
190
191 /*******************************************************************************
192  *
193  * FUNCTION:    acpi_ut_print_string
194  *
195  * PARAMETERS:  String          - Null terminated ASCII string
196  *              max_length      - Maximum output length
197  *
198  * RETURN:      None
199  *
200  * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
201  *              sequences.
202  *
203  ******************************************************************************/
204
205 void acpi_ut_print_string(char *string, u8 max_length)
206 {
207         u32 i;
208
209         if (!string) {
210                 acpi_os_printf("<\"NULL STRING PTR\">");
211                 return;
212         }
213
214         acpi_os_printf("\"");
215         for (i = 0; string[i] && (i < max_length); i++) {
216                 /* Escape sequences */
217
218                 switch (string[i]) {
219                 case 0x07:
220                         acpi_os_printf("\\a");  /* BELL */
221                         break;
222
223                 case 0x08:
224                         acpi_os_printf("\\b");  /* BACKSPACE */
225                         break;
226
227                 case 0x0C:
228                         acpi_os_printf("\\f");  /* FORMFEED */
229                         break;
230
231                 case 0x0A:
232                         acpi_os_printf("\\n");  /* LINEFEED */
233                         break;
234
235                 case 0x0D:
236                         acpi_os_printf("\\r");  /* CARRIAGE RETURN */
237                         break;
238
239                 case 0x09:
240                         acpi_os_printf("\\t");  /* HORIZONTAL TAB */
241                         break;
242
243                 case 0x0B:
244                         acpi_os_printf("\\v");  /* VERTICAL TAB */
245                         break;
246
247                 case '\'':      /* Single Quote */
248                 case '\"':      /* Double Quote */
249                 case '\\':      /* Backslash */
250                         acpi_os_printf("\\%c", (int)string[i]);
251                         break;
252
253                 default:
254
255                         /* Check for printable character or hex escape */
256
257                         if (ACPI_IS_PRINT(string[i])) {
258                                 /* This is a normal character */
259
260                                 acpi_os_printf("%c", (int)string[i]);
261                         } else {
262                                 /* All others will be Hex escapes */
263
264                                 acpi_os_printf("\\x%2.2X", (s32) string[i]);
265                         }
266                         break;
267                 }
268         }
269         acpi_os_printf("\"");
270
271         if (i == max_length && string[i]) {
272                 acpi_os_printf("...");
273         }
274 }
275
276 /*******************************************************************************
277  *
278  * FUNCTION:    acpi_ut_dword_byte_swap
279  *
280  * PARAMETERS:  Value           - Value to be converted
281  *
282  * RETURN:      u32 integer with bytes swapped
283  *
284  * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
285  *
286  ******************************************************************************/
287
288 u32 acpi_ut_dword_byte_swap(u32 value)
289 {
290         union {
291                 u32 value;
292                 u8 bytes[4];
293         } out;
294         union {
295                 u32 value;
296                 u8 bytes[4];
297         } in;
298
299         ACPI_FUNCTION_ENTRY();
300
301         in.value = value;
302
303         out.bytes[0] = in.bytes[3];
304         out.bytes[1] = in.bytes[2];
305         out.bytes[2] = in.bytes[1];
306         out.bytes[3] = in.bytes[0];
307
308         return (out.value);
309 }
310
311 /*******************************************************************************
312  *
313  * FUNCTION:    acpi_ut_set_integer_width
314  *
315  * PARAMETERS:  Revision            From DSDT header
316  *
317  * RETURN:      None
318  *
319  * DESCRIPTION: Set the global integer bit width based upon the revision
320  *              of the DSDT.  For Revision 1 and 0, Integers are 32 bits.
321  *              For Revision 2 and above, Integers are 64 bits.  Yes, this
322  *              makes a difference.
323  *
324  ******************************************************************************/
325
326 void acpi_ut_set_integer_width(u8 revision)
327 {
328
329         if (revision <= 1) {
330                 acpi_gbl_integer_bit_width = 32;
331                 acpi_gbl_integer_nybble_width = 8;
332                 acpi_gbl_integer_byte_width = 4;
333         } else {
334                 acpi_gbl_integer_bit_width = 64;
335                 acpi_gbl_integer_nybble_width = 16;
336                 acpi_gbl_integer_byte_width = 8;
337         }
338 }
339
340 #ifdef ACPI_DEBUG_OUTPUT
341 /*******************************************************************************
342  *
343  * FUNCTION:    acpi_ut_display_init_pathname
344  *
345  * PARAMETERS:  Type                - Object type of the node
346  *              obj_handle          - Handle whose pathname will be displayed
347  *              Path                - Additional path string to be appended.
348  *                                      (NULL if no extra path)
349  *
350  * RETURN:      acpi_status
351  *
352  * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
353  *
354  ******************************************************************************/
355
356 void
357 acpi_ut_display_init_pathname(u8 type,
358                               struct acpi_namespace_node *obj_handle,
359                               char *path)
360 {
361         acpi_status status;
362         struct acpi_buffer buffer;
363
364         ACPI_FUNCTION_ENTRY();
365
366         /* Only print the path if the appropriate debug level is enabled */
367
368         if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
369                 return;
370         }
371
372         /* Get the full pathname to the node */
373
374         buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
375         status = acpi_ns_handle_to_pathname(obj_handle, &buffer);
376         if (ACPI_FAILURE(status)) {
377                 return;
378         }
379
380         /* Print what we're doing */
381
382         switch (type) {
383         case ACPI_TYPE_METHOD:
384                 acpi_os_printf("Executing  ");
385                 break;
386
387         default:
388                 acpi_os_printf("Initializing ");
389                 break;
390         }
391
392         /* Print the object type and pathname */
393
394         acpi_os_printf("%-12s %s",
395                        acpi_ut_get_type_name(type), (char *)buffer.pointer);
396
397         /* Extra path is used to append names like _STA, _INI, etc. */
398
399         if (path) {
400                 acpi_os_printf(".%s", path);
401         }
402         acpi_os_printf("\n");
403
404         ACPI_MEM_FREE(buffer.pointer);
405 }
406 #endif
407
408 /*******************************************************************************
409  *
410  * FUNCTION:    acpi_ut_valid_acpi_name
411  *
412  * PARAMETERS:  Name            - The name to be examined
413  *
414  * RETURN:      TRUE if the name is valid, FALSE otherwise
415  *
416  * DESCRIPTION: Check for a valid ACPI name.  Each character must be one of:
417  *              1) Upper case alpha
418  *              2) numeric
419  *              3) underscore
420  *
421  ******************************************************************************/
422
423 u8 acpi_ut_valid_acpi_name(u32 name)
424 {
425         char *name_ptr = (char *)&name;
426         char character;
427         acpi_native_uint i;
428
429         ACPI_FUNCTION_ENTRY();
430
431         for (i = 0; i < ACPI_NAME_SIZE; i++) {
432                 character = *name_ptr;
433                 name_ptr++;
434
435                 if (!((character == '_') ||
436                       (character >= 'A' && character <= 'Z') ||
437                       (character >= '0' && character <= '9'))) {
438                         return (FALSE);
439                 }
440         }
441
442         return (TRUE);
443 }
444
445 /*******************************************************************************
446  *
447  * FUNCTION:    acpi_ut_valid_acpi_character
448  *
449  * PARAMETERS:  Character           - The character to be examined
450  *
451  * RETURN:      1 if Character may appear in a name, else 0
452  *
453  * DESCRIPTION: Check for a printable character
454  *
455  ******************************************************************************/
456
457 u8 acpi_ut_valid_acpi_character(char character)
458 {
459
460         ACPI_FUNCTION_ENTRY();
461
462         return ((u8) ((character == '_') ||
463                       (character >= 'A' && character <= 'Z') ||
464                       (character >= '0' && character <= '9')));
465 }
466
467 /*******************************************************************************
468  *
469  * FUNCTION:    acpi_ut_strtoul64
470  *
471  * PARAMETERS:  String          - Null terminated string
472  *              Base            - Radix of the string: 10, 16, or ACPI_ANY_BASE
473  *              ret_integer     - Where the converted integer is returned
474  *
475  * RETURN:      Status and Converted value
476  *
477  * DESCRIPTION: Convert a string into an unsigned value.
478  *              NOTE: Does not support Octal strings, not needed.
479  *
480  ******************************************************************************/
481
482 acpi_status
483 acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
484 {
485         u32 this_digit = 0;
486         acpi_integer return_value = 0;
487         acpi_integer quotient;
488
489         ACPI_FUNCTION_TRACE("ut_stroul64");
490
491         if ((!string) || !(*string)) {
492                 goto error_exit;
493         }
494
495         switch (base) {
496         case ACPI_ANY_BASE:
497         case 10:
498         case 16:
499                 break;
500
501         default:
502                 /* Invalid Base */
503                 return_ACPI_STATUS(AE_BAD_PARAMETER);
504         }
505
506         /* Skip over any white space in the buffer */
507
508         while (ACPI_IS_SPACE(*string) || *string == '\t') {
509                 string++;
510         }
511
512         /*
513          * If the input parameter Base is zero, then we need to
514          * determine if it is decimal or hexadecimal:
515          */
516         if (base == 0) {
517                 if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) {
518                         base = 16;
519                         string += 2;
520                 } else {
521                         base = 10;
522                 }
523         }
524
525         /*
526          * For hexadecimal base, skip over the leading
527          * 0 or 0x, if they are present.
528          */
529         if ((base == 16) &&
530             (*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) {
531                 string += 2;
532         }
533
534         /* Any string left? */
535
536         if (!(*string)) {
537                 goto error_exit;
538         }
539
540         /* Main loop: convert the string to a 64-bit integer */
541
542         while (*string) {
543                 if (ACPI_IS_DIGIT(*string)) {
544                         /* Convert ASCII 0-9 to Decimal value */
545
546                         this_digit = ((u8) * string) - '0';
547                 } else {
548                         if (base == 10) {
549                                 /* Digit is out of range */
550
551                                 goto error_exit;
552                         }
553
554                         this_digit = (u8) ACPI_TOUPPER(*string);
555                         if (ACPI_IS_XDIGIT((char)this_digit)) {
556                                 /* Convert ASCII Hex char to value */
557
558                                 this_digit = this_digit - 'A' + 10;
559                         } else {
560                                 /*
561                                  * We allow non-hex chars, just stop now, same as end-of-string.
562                                  * See ACPI spec, string-to-integer conversion.
563                                  */
564                                 break;
565                         }
566                 }
567
568                 /* Divide the digit into the correct position */
569
570                 (void)
571                     acpi_ut_short_divide((ACPI_INTEGER_MAX -
572                                           (acpi_integer) this_digit), base,
573                                          &quotient, NULL);
574                 if (return_value > quotient) {
575                         goto error_exit;
576                 }
577
578                 return_value *= base;
579                 return_value += this_digit;
580                 string++;
581         }
582
583         /* All done, normal exit */
584
585         *ret_integer = return_value;
586         return_ACPI_STATUS(AE_OK);
587
588       error_exit:
589         /* Base was set/validated above */
590
591         if (base == 10) {
592                 return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT);
593         } else {
594                 return_ACPI_STATUS(AE_BAD_HEX_CONSTANT);
595         }
596 }
597
598 /*******************************************************************************
599  *
600  * FUNCTION:    acpi_ut_create_update_state_and_push
601  *
602  * PARAMETERS:  Object          - Object to be added to the new state
603  *              Action          - Increment/Decrement
604  *              state_list      - List the state will be added to
605  *
606  * RETURN:      Status
607  *
608  * DESCRIPTION: Create a new state and push it
609  *
610  ******************************************************************************/
611
612 acpi_status
613 acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
614                                      u16 action,
615                                      union acpi_generic_state **state_list)
616 {
617         union acpi_generic_state *state;
618
619         ACPI_FUNCTION_ENTRY();
620
621         /* Ignore null objects; these are expected */
622
623         if (!object) {
624                 return (AE_OK);
625         }
626
627         state = acpi_ut_create_update_state(object, action);
628         if (!state) {
629                 return (AE_NO_MEMORY);
630         }
631
632         acpi_ut_push_generic_state(state_list, state);
633         return (AE_OK);
634 }
635
636 /*******************************************************************************
637  *
638  * FUNCTION:    acpi_ut_walk_package_tree
639  *
640  * PARAMETERS:  source_object       - The package to walk
641  *              target_object       - Target object (if package is being copied)
642  *              walk_callback       - Called once for each package element
643  *              Context             - Passed to the callback function
644  *
645  * RETURN:      Status
646  *
647  * DESCRIPTION: Walk through a package
648  *
649  ******************************************************************************/
650
651 acpi_status
652 acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
653                           void *target_object,
654                           acpi_pkg_callback walk_callback, void *context)
655 {
656         acpi_status status = AE_OK;
657         union acpi_generic_state *state_list = NULL;
658         union acpi_generic_state *state;
659         u32 this_index;
660         union acpi_operand_object *this_source_obj;
661
662         ACPI_FUNCTION_TRACE("ut_walk_package_tree");
663
664         state = acpi_ut_create_pkg_state(source_object, target_object, 0);
665         if (!state) {
666                 return_ACPI_STATUS(AE_NO_MEMORY);
667         }
668
669         while (state) {
670                 /* Get one element of the package */
671
672                 this_index = state->pkg.index;
673                 this_source_obj = (union acpi_operand_object *)
674                     state->pkg.source_object->package.elements[this_index];
675
676                 /*
677                  * Check for:
678                  * 1) An uninitialized package element.  It is completely
679                  *    legal to declare a package and leave it uninitialized
680                  * 2) Not an internal object - can be a namespace node instead
681                  * 3) Any type other than a package.  Packages are handled in else
682                  *    case below.
683                  */
684                 if ((!this_source_obj) ||
685                     (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) !=
686                      ACPI_DESC_TYPE_OPERAND)
687                     || (ACPI_GET_OBJECT_TYPE(this_source_obj) !=
688                         ACPI_TYPE_PACKAGE)) {
689                         status =
690                             walk_callback(ACPI_COPY_TYPE_SIMPLE,
691                                           this_source_obj, state, context);
692                         if (ACPI_FAILURE(status)) {
693                                 return_ACPI_STATUS(status);
694                         }
695
696                         state->pkg.index++;
697                         while (state->pkg.index >=
698                                state->pkg.source_object->package.count) {
699                                 /*
700                                  * We've handled all of the objects at this level,  This means
701                                  * that we have just completed a package.  That package may
702                                  * have contained one or more packages itself.
703                                  *
704                                  * Delete this state and pop the previous state (package).
705                                  */
706                                 acpi_ut_delete_generic_state(state);
707                                 state = acpi_ut_pop_generic_state(&state_list);
708
709                                 /* Finished when there are no more states */
710
711                                 if (!state) {
712                                         /*
713                                          * We have handled all of the objects in the top level
714                                          * package just add the length of the package objects
715                                          * and exit
716                                          */
717                                         return_ACPI_STATUS(AE_OK);
718                                 }
719
720                                 /*
721                                  * Go back up a level and move the index past the just
722                                  * completed package object.
723                                  */
724                                 state->pkg.index++;
725                         }
726                 } else {
727                         /* This is a subobject of type package */
728
729                         status =
730                             walk_callback(ACPI_COPY_TYPE_PACKAGE,
731                                           this_source_obj, state, context);
732                         if (ACPI_FAILURE(status)) {
733                                 return_ACPI_STATUS(status);
734                         }
735
736                         /*
737                          * Push the current state and create a new one
738                          * The callback above returned a new target package object.
739                          */
740                         acpi_ut_push_generic_state(&state_list, state);
741                         state = acpi_ut_create_pkg_state(this_source_obj,
742                                                          state->pkg.
743                                                          this_target_obj, 0);
744                         if (!state) {
745                                 return_ACPI_STATUS(AE_NO_MEMORY);
746                         }
747                 }
748         }
749
750         /* We should never get here */
751
752         return_ACPI_STATUS(AE_AML_INTERNAL);
753 }
754
755 /*******************************************************************************
756  *
757  * FUNCTION:    acpi_ut_generate_checksum
758  *
759  * PARAMETERS:  Buffer          - Buffer to be scanned
760  *              Length          - number of bytes to examine
761  *
762  * RETURN:      The generated checksum
763  *
764  * DESCRIPTION: Generate a checksum on a raw buffer
765  *
766  ******************************************************************************/
767
768 u8 acpi_ut_generate_checksum(u8 * buffer, u32 length)
769 {
770         u32 i;
771         signed char sum = 0;
772
773         for (i = 0; i < length; i++) {
774                 sum = (signed char)(sum + buffer[i]);
775         }
776
777         return ((u8) (0 - sum));
778 }
779
780 /*******************************************************************************
781  *
782  * FUNCTION:    acpi_ut_get_resource_end_tag
783  *
784  * PARAMETERS:  obj_desc        - The resource template buffer object
785  *
786  * RETURN:      Pointer to the end tag
787  *
788  * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
789  *
790  ******************************************************************************/
791
792 u8 *acpi_ut_get_resource_end_tag(union acpi_operand_object * obj_desc)
793 {
794         u8 buffer_byte;
795         u8 *buffer;
796         u8 *end_buffer;
797
798         buffer = obj_desc->buffer.pointer;
799         end_buffer = buffer + obj_desc->buffer.length;
800
801         while (buffer < end_buffer) {
802                 buffer_byte = *buffer;
803                 if (buffer_byte & ACPI_RDESC_TYPE_MASK) {
804                         /* Large Descriptor - Length is next 2 bytes */
805
806                         buffer += ((*(buffer + 1) | (*(buffer + 2) << 8)) + 3);
807                 } else {
808                         /* Small Descriptor.  End Tag will be found here */
809
810                         if ((buffer_byte & ACPI_RDESC_SMALL_MASK) ==
811                             ACPI_RDESC_TYPE_END_TAG) {
812                                 /* Found the end tag descriptor, all done. */
813
814                                 return (buffer);
815                         }
816
817                         /* Length is in the header */
818
819                         buffer += ((buffer_byte & 0x07) + 1);
820                 }
821         }
822
823         /* End tag not found */
824
825         return (NULL);
826 }
827
828 /*******************************************************************************
829  *
830  * FUNCTION:    acpi_ut_report_error
831  *
832  * PARAMETERS:  module_name         - Caller's module name (for error output)
833  *              line_number         - Caller's line number (for error output)
834  *              component_id        - Caller's component ID (for error output)
835  *
836  * RETURN:      None
837  *
838  * DESCRIPTION: Print error message
839  *
840  ******************************************************************************/
841
842 void acpi_ut_report_error(char *module_name, u32 line_number, u32 component_id)
843 {
844
845         acpi_os_printf("%8s-%04d: *** Error: ", module_name, line_number);
846 }
847
848 /*******************************************************************************
849  *
850  * FUNCTION:    acpi_ut_report_warning
851  *
852  * PARAMETERS:  module_name         - Caller's module name (for error output)
853  *              line_number         - Caller's line number (for error output)
854  *              component_id        - Caller's component ID (for error output)
855  *
856  * RETURN:      None
857  *
858  * DESCRIPTION: Print warning message
859  *
860  ******************************************************************************/
861
862 void
863 acpi_ut_report_warning(char *module_name, u32 line_number, u32 component_id)
864 {
865
866         acpi_os_printf("%8s-%04d: *** Warning: ", module_name, line_number);
867 }
868
869 /*******************************************************************************
870  *
871  * FUNCTION:    acpi_ut_report_info
872  *
873  * PARAMETERS:  module_name         - Caller's module name (for error output)
874  *              line_number         - Caller's line number (for error output)
875  *              component_id        - Caller's component ID (for error output)
876  *
877  * RETURN:      None
878  *
879  * DESCRIPTION: Print information message
880  *
881  ******************************************************************************/
882
883 void acpi_ut_report_info(char *module_name, u32 line_number, u32 component_id)
884 {
885
886         acpi_os_printf("%8s-%04d: *** Info: ", module_name, line_number);
887 }