utmisc.c (45dcd31547fcd58273423799b12efe0e8371127e) utmisc.c (6d33b6be17dd6a0934396704f969ceb7f3206347)
1/*******************************************************************************
2 *
3 * Module Name: utmisc - common utility procedures
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2012, Intel Corp.

--- 27 unchanged lines hidden (view full) ---

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
1/*******************************************************************************
2 *
3 * Module Name: utmisc - common utility procedures
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2012, Intel Corp.

--- 27 unchanged lines hidden (view full) ---

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 <linux/module.h>
45
46#include <acpi/acpi.h>
47#include "accommon.h"
48#include "acnamesp.h"
49
50#define _COMPONENT ACPI_UTILITIES
51ACPI_MODULE_NAME("utmisc")
52
53#if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP

--- 142 unchanged lines hidden (view full) ---

196 if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) {
197 /*
198 * Found a free ID. The actual ID is the bit index plus one,
199 * making zero an invalid Owner ID. Save this as the last ID
200 * allocated and update the global ID mask.
201 */
202 acpi_gbl_owner_id_mask[j] |= (1 << k);
203
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "acnamesp.h"
47
48#define _COMPONENT ACPI_UTILITIES
49ACPI_MODULE_NAME("utmisc")
50
51#if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP

--- 142 unchanged lines hidden (view full) ---

194 if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) {
195 /*
196 * Found a free ID. The actual ID is the bit index plus one,
197 * making zero an invalid Owner ID. Save this as the last ID
198 * allocated and update the global ID mask.
199 */
200 acpi_gbl_owner_id_mask[j] |= (1 << k);
201
204 acpi_gbl_last_owner_id_index = (u8) j;
205 acpi_gbl_next_owner_id_offset = (u8) (k + 1);
202 acpi_gbl_last_owner_id_index = (u8)j;
203 acpi_gbl_next_owner_id_offset = (u8)(k + 1);
206
207 /*
208 * Construct encoded ID from the index and bit position
209 *
210 * Note: Last [j].k (bit 255) is never used and is marked
211 * permanently allocated (prevents +1 overflow)
212 */
213 *owner_id =

--- 120 unchanged lines hidden (view full) ---

334
335 for (string = src_string; *string; string++) {
336 *string = (char)ACPI_TOUPPER(*string);
337 }
338
339 return;
340}
341
204
205 /*
206 * Construct encoded ID from the index and bit position
207 *
208 * Note: Last [j].k (bit 255) is never used and is marked
209 * permanently allocated (prevents +1 overflow)
210 */
211 *owner_id =

--- 120 unchanged lines hidden (view full) ---

332
333 for (string = src_string; *string; string++) {
334 *string = (char)ACPI_TOUPPER(*string);
335 }
336
337 return;
338}
339
340#ifdef ACPI_ASL_COMPILER
342/*******************************************************************************
343 *
341/*******************************************************************************
342 *
343 * FUNCTION: acpi_ut_strlwr (strlwr)
344 *
345 * PARAMETERS: src_string - The source string to convert
346 *
347 * RETURN: None
348 *
349 * DESCRIPTION: Convert string to lowercase
350 *
351 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
352 *
353 ******************************************************************************/
354
355void acpi_ut_strlwr(char *src_string)
356{
357 char *string;
358
359 ACPI_FUNCTION_ENTRY();
360
361 if (!src_string) {
362 return;
363 }
364
365 /* Walk entire string, lowercasing the letters */
366
367 for (string = src_string; *string; string++) {
368 *string = (char)ACPI_TOLOWER(*string);
369 }
370
371 return;
372}
373
374/******************************************************************************
375 *
376 * FUNCTION: acpi_ut_stricmp
377 *
378 * PARAMETERS: string1 - first string to compare
379 * string2 - second string to compare
380 *
381 * RETURN: int that signifies string relationship. Zero means strings
382 * are equal.
383 *
384 * DESCRIPTION: Implementation of the non-ANSI stricmp function (compare
385 * strings with no case sensitivity)
386 *
387 ******************************************************************************/
388
389int acpi_ut_stricmp(char *string1, char *string2)
390{
391 int c1;
392 int c2;
393
394 do {
395 c1 = tolower((int)*string1);
396 c2 = tolower((int)*string2);
397
398 string1++;
399 string2++;
400 }
401 while ((c1 == c2) && (c1));
402
403 return (c1 - c2);
404}
405#endif
406
407/*******************************************************************************
408 *
344 * FUNCTION: acpi_ut_print_string
345 *
346 * PARAMETERS: string - Null terminated ASCII string
347 * max_length - Maximum output length
348 *
349 * RETURN: None
350 *
351 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape

--- 281 unchanged lines hidden (view full) ---

633 *
634 * FUNCTION: acpi_ut_repair_name
635 *
636 * PARAMETERS: name - The ACPI name to be repaired
637 *
638 * RETURN: Repaired version of the name
639 *
640 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
409 * FUNCTION: acpi_ut_print_string
410 *
411 * PARAMETERS: string - Null terminated ASCII string
412 * max_length - Maximum output length
413 *
414 * RETURN: None
415 *
416 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape

--- 281 unchanged lines hidden (view full) ---

698 *
699 * FUNCTION: acpi_ut_repair_name
700 *
701 * PARAMETERS: name - The ACPI name to be repaired
702 *
703 * RETURN: Repaired version of the name
704 *
705 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
641 * return the new name.
706 * return the new name. NOTE: the Name parameter must reside in
707 * read/write memory, cannot be a const.
642 *
708 *
709 * An ACPI Name must consist of valid ACPI characters. We will repair the name
710 * if necessary because we don't want to abort because of this, but we want
711 * all namespace names to be printable. A warning message is appropriate.
712 *
713 * This issue came up because there are in fact machines that exhibit
714 * this problem, and we want to be able to enable ACPI support for them,
715 * even though there are a few bad names.
716 *
643 ******************************************************************************/
644
645void acpi_ut_repair_name(char *name)
646{
647 u32 i;
648 u8 found_bad_char = FALSE;
649
650 ACPI_FUNCTION_NAME(ut_repair_name);

--- 43 unchanged lines hidden (view full) ---

694 *
695 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
696 * 32-bit or 64-bit conversion, depending on the current mode
697 * of the interpreter.
698 * NOTE: Does not support Octal strings, not needed.
699 *
700 ******************************************************************************/
701
717 ******************************************************************************/
718
719void acpi_ut_repair_name(char *name)
720{
721 u32 i;
722 u8 found_bad_char = FALSE;
723
724 ACPI_FUNCTION_NAME(ut_repair_name);

--- 43 unchanged lines hidden (view full) ---

768 *
769 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
770 * 32-bit or 64-bit conversion, depending on the current mode
771 * of the interpreter.
772 * NOTE: Does not support Octal strings, not needed.
773 *
774 ******************************************************************************/
775
702acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 * ret_integer)
776acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 *ret_integer)
703{
704 u32 this_digit = 0;
705 u64 return_value = 0;
706 u64 quotient;
707 u64 dividend;
708 u32 to_integer_op = (base == ACPI_ANY_BASE);
709 u32 mode32 = (acpi_gbl_integer_byte_width == 4);
710 u8 valid_digits = 0;

--- 56 unchanged lines hidden (view full) ---

767
768 /* Main loop: convert the string to a 32- or 64-bit integer */
769
770 while (*string) {
771 if (ACPI_IS_DIGIT(*string)) {
772
773 /* Convert ASCII 0-9 to Decimal value */
774
777{
778 u32 this_digit = 0;
779 u64 return_value = 0;
780 u64 quotient;
781 u64 dividend;
782 u32 to_integer_op = (base == ACPI_ANY_BASE);
783 u32 mode32 = (acpi_gbl_integer_byte_width == 4);
784 u8 valid_digits = 0;

--- 56 unchanged lines hidden (view full) ---

841
842 /* Main loop: convert the string to a 32- or 64-bit integer */
843
844 while (*string) {
845 if (ACPI_IS_DIGIT(*string)) {
846
847 /* Convert ASCII 0-9 to Decimal value */
848
775 this_digit = ((u8) * string) - '0';
849 this_digit = ((u8)*string) - '0';
776 } else if (base == 10) {
777
778 /* Digit is out of range; possible in to_integer case only */
779
780 term = 1;
781 } else {
850 } else if (base == 10) {
851
852 /* Digit is out of range; possible in to_integer case only */
853
854 term = 1;
855 } else {
782 this_digit = (u8) ACPI_TOUPPER(*string);
856 this_digit = (u8)ACPI_TOUPPER(*string);
783 if (ACPI_IS_XDIGIT((char)this_digit)) {
784
785 /* Convert ASCII Hex char to value */
786
787 this_digit = this_digit - 'A' + 10;
788 } else {
789 term = 1;
790 }

--- 10 unchanged lines hidden (view full) ---

801
802 /* Skip zeros */
803 string++;
804 continue;
805 }
806
807 valid_digits++;
808
857 if (ACPI_IS_XDIGIT((char)this_digit)) {
858
859 /* Convert ASCII Hex char to value */
860
861 this_digit = this_digit - 'A' + 10;
862 } else {
863 term = 1;
864 }

--- 10 unchanged lines hidden (view full) ---

875
876 /* Skip zeros */
877 string++;
878 continue;
879 }
880
881 valid_digits++;
882
809 if (sign_of0x && ((valid_digits > 16)
810 || ((valid_digits > 8) && mode32))) {
883 if (sign_of0x
884 && ((valid_digits > 16)
885 || ((valid_digits > 8) && mode32))) {
811 /*
812 * This is to_integer operation case.
813 * No any restrictions for string-to-integer conversion,
814 * see ACPI spec.
815 */
816 goto error_exit;
817 }
818
819 /* Divide the digit into the correct position */
820
886 /*
887 * This is to_integer operation case.
888 * No any restrictions for string-to-integer conversion,
889 * see ACPI spec.
890 */
891 goto error_exit;
892 }
893
894 /* Divide the digit into the correct position */
895
821 (void)acpi_ut_short_divide((dividend - (u64) this_digit),
896 (void)acpi_ut_short_divide((dividend - (u64)this_digit),
822 base, &quotient, NULL);
823
824 if (return_value > quotient) {
825 if (to_integer_op) {
826 goto error_exit;
827 } else {
828 break;
829 }

--- 73 unchanged lines hidden (view full) ---

903 *
904 * RETURN: Status
905 *
906 * DESCRIPTION: Walk through a package
907 *
908 ******************************************************************************/
909
910acpi_status
897 base, &quotient, NULL);
898
899 if (return_value > quotient) {
900 if (to_integer_op) {
901 goto error_exit;
902 } else {
903 break;
904 }

--- 73 unchanged lines hidden (view full) ---

978 *
979 * RETURN: Status
980 *
981 * DESCRIPTION: Walk through a package
982 *
983 ******************************************************************************/
984
985acpi_status
911acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
986acpi_ut_walk_package_tree(union acpi_operand_object *source_object,
912 void *target_object,
913 acpi_pkg_callback walk_callback, void *context)
914{
915 acpi_status status = AE_OK;
916 union acpi_generic_state *state_list = NULL;
917 union acpi_generic_state *state;
918 u32 this_index;
919 union acpi_operand_object *this_source_obj;

--- 102 unchanged lines hidden ---
987 void *target_object,
988 acpi_pkg_callback walk_callback, void *context)
989{
990 acpi_status status = AE_OK;
991 union acpi_generic_state *state_list = NULL;
992 union acpi_generic_state *state;
993 u32 this_index;
994 union acpi_operand_object *this_source_obj;

--- 102 unchanged lines hidden ---