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