diff options
Diffstat (limited to 'drivers/acpi/utilities/utmisc.c')
-rw-r--r-- | drivers/acpi/utilities/utmisc.c | 209 |
1 files changed, 123 insertions, 86 deletions
diff --git a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c index 2ce872d75890..7364f5f8c9cd 100644 --- a/drivers/acpi/utilities/utmisc.c +++ b/drivers/acpi/utilities/utmisc.c | |||
@@ -5,7 +5,7 @@ | |||
5 | ******************************************************************************/ | 5 | ******************************************************************************/ |
6 | 6 | ||
7 | /* | 7 | /* |
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
9 | * All rights reserved. | 9 | * All rights reserved. |
10 | * | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without |
@@ -63,6 +63,8 @@ ACPI_MODULE_NAME("utmisc") | |||
63 | acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id) | 63 | acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id) |
64 | { | 64 | { |
65 | acpi_native_uint i; | 65 | acpi_native_uint i; |
66 | acpi_native_uint j; | ||
67 | acpi_native_uint k; | ||
66 | acpi_status status; | 68 | acpi_status status; |
67 | 69 | ||
68 | ACPI_FUNCTION_TRACE("ut_allocate_owner_id"); | 70 | ACPI_FUNCTION_TRACE("ut_allocate_owner_id"); |
@@ -70,8 +72,8 @@ acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id) | |||
70 | /* Guard against multiple allocations of ID to the same location */ | 72 | /* Guard against multiple allocations of ID to the same location */ |
71 | 73 | ||
72 | if (*owner_id) { | 74 | if (*owner_id) { |
73 | ACPI_REPORT_ERROR(("Owner ID [%2.2X] already exists\n", | 75 | ACPI_ERROR((AE_INFO, "Owner ID [%2.2X] already exists", |
74 | *owner_id)); | 76 | *owner_id)); |
75 | return_ACPI_STATUS(AE_ALREADY_EXISTS); | 77 | return_ACPI_STATUS(AE_ALREADY_EXISTS); |
76 | } | 78 | } |
77 | 79 | ||
@@ -82,31 +84,67 @@ acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id) | |||
82 | return_ACPI_STATUS(status); | 84 | return_ACPI_STATUS(status); |
83 | } | 85 | } |
84 | 86 | ||
85 | /* Find a free owner ID */ | 87 | /* |
88 | * Find a free owner ID, cycle through all possible IDs on repeated | ||
89 | * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have | ||
90 | * to be scanned twice. | ||
91 | */ | ||
92 | for (i = 0, j = acpi_gbl_last_owner_id_index; | ||
93 | i < (ACPI_NUM_OWNERID_MASKS + 1); i++, j++) { | ||
94 | if (j >= ACPI_NUM_OWNERID_MASKS) { | ||
95 | j = 0; /* Wraparound to start of mask array */ | ||
96 | } | ||
97 | |||
98 | for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) { | ||
99 | if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) { | ||
100 | /* There are no free IDs in this mask */ | ||
86 | 101 | ||
87 | for (i = 0; i < 64; i++) { | 102 | break; |
88 | if (!(acpi_gbl_owner_id_mask & (1ULL << i))) { | 103 | } |
89 | ACPI_DEBUG_PRINT((ACPI_DB_VALUES, | ||
90 | "Current owner_id mask: %16.16LX New ID: %2.2X\n", | ||
91 | acpi_gbl_owner_id_mask, | ||
92 | (unsigned int)(i + 1))); | ||
93 | 104 | ||
94 | acpi_gbl_owner_id_mask |= (1ULL << i); | 105 | if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) { |
95 | *owner_id = (acpi_owner_id) (i + 1); | 106 | /* |
96 | goto exit; | 107 | * Found a free ID. The actual ID is the bit index plus one, |
108 | * making zero an invalid Owner ID. Save this as the last ID | ||
109 | * allocated and update the global ID mask. | ||
110 | */ | ||
111 | acpi_gbl_owner_id_mask[j] |= (1 << k); | ||
112 | |||
113 | acpi_gbl_last_owner_id_index = (u8) j; | ||
114 | acpi_gbl_next_owner_id_offset = (u8) (k + 1); | ||
115 | |||
116 | /* | ||
117 | * Construct encoded ID from the index and bit position | ||
118 | * | ||
119 | * Note: Last [j].k (bit 255) is never used and is marked | ||
120 | * permanently allocated (prevents +1 overflow) | ||
121 | */ | ||
122 | *owner_id = | ||
123 | (acpi_owner_id) ((k + 1) + ACPI_MUL_32(j)); | ||
124 | |||
125 | ACPI_DEBUG_PRINT((ACPI_DB_VALUES, | ||
126 | "Allocated owner_id: %2.2X\n", | ||
127 | (unsigned int)*owner_id)); | ||
128 | goto exit; | ||
129 | } | ||
97 | } | 130 | } |
131 | |||
132 | acpi_gbl_next_owner_id_offset = 0; | ||
98 | } | 133 | } |
99 | 134 | ||
100 | /* | 135 | /* |
101 | * If we are here, all owner_ids have been allocated. This probably should | 136 | * All owner_ids have been allocated. This typically should |
102 | * not happen since the IDs are reused after deallocation. The IDs are | 137 | * not happen since the IDs are reused after deallocation. The IDs are |
103 | * allocated upon table load (one per table) and method execution, and | 138 | * allocated upon table load (one per table) and method execution, and |
104 | * they are released when a table is unloaded or a method completes | 139 | * they are released when a table is unloaded or a method completes |
105 | * execution. | 140 | * execution. |
141 | * | ||
142 | * If this error happens, there may be very deep nesting of invoked control | ||
143 | * methods, or there may be a bug where the IDs are not released. | ||
106 | */ | 144 | */ |
107 | *owner_id = 0; | ||
108 | status = AE_OWNER_ID_LIMIT; | 145 | status = AE_OWNER_ID_LIMIT; |
109 | ACPI_REPORT_ERROR(("Could not allocate new owner_id (64 max), AE_OWNER_ID_LIMIT\n")); | 146 | ACPI_ERROR((AE_INFO, |
147 | "Could not allocate new owner_id (255 max), AE_OWNER_ID_LIMIT")); | ||
110 | 148 | ||
111 | exit: | 149 | exit: |
112 | (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); | 150 | (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); |
@@ -123,7 +161,7 @@ acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id) | |||
123 | * control method or unloading a table. Either way, we would | 161 | * control method or unloading a table. Either way, we would |
124 | * ignore any error anyway. | 162 | * ignore any error anyway. |
125 | * | 163 | * |
126 | * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 64 | 164 | * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255 |
127 | * | 165 | * |
128 | ******************************************************************************/ | 166 | ******************************************************************************/ |
129 | 167 | ||
@@ -131,6 +169,8 @@ void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr) | |||
131 | { | 169 | { |
132 | acpi_owner_id owner_id = *owner_id_ptr; | 170 | acpi_owner_id owner_id = *owner_id_ptr; |
133 | acpi_status status; | 171 | acpi_status status; |
172 | acpi_native_uint index; | ||
173 | u32 bit; | ||
134 | 174 | ||
135 | ACPI_FUNCTION_TRACE_U32("ut_release_owner_id", owner_id); | 175 | ACPI_FUNCTION_TRACE_U32("ut_release_owner_id", owner_id); |
136 | 176 | ||
@@ -140,8 +180,8 @@ void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr) | |||
140 | 180 | ||
141 | /* Zero is not a valid owner_iD */ | 181 | /* Zero is not a valid owner_iD */ |
142 | 182 | ||
143 | if ((owner_id == 0) || (owner_id > 64)) { | 183 | if (owner_id == 0) { |
144 | ACPI_REPORT_ERROR(("Invalid owner_id: %2.2X\n", owner_id)); | 184 | ACPI_ERROR((AE_INFO, "Invalid owner_id: %2.2X", owner_id)); |
145 | return_VOID; | 185 | return_VOID; |
146 | } | 186 | } |
147 | 187 | ||
@@ -156,10 +196,19 @@ void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr) | |||
156 | 196 | ||
157 | owner_id--; | 197 | owner_id--; |
158 | 198 | ||
199 | /* Decode ID to index/offset pair */ | ||
200 | |||
201 | index = ACPI_DIV_32(owner_id); | ||
202 | bit = 1 << ACPI_MOD_32(owner_id); | ||
203 | |||
159 | /* Free the owner ID only if it is valid */ | 204 | /* Free the owner ID only if it is valid */ |
160 | 205 | ||
161 | if (acpi_gbl_owner_id_mask & (1ULL << owner_id)) { | 206 | if (acpi_gbl_owner_id_mask[index] & bit) { |
162 | acpi_gbl_owner_id_mask ^= (1ULL << owner_id); | 207 | acpi_gbl_owner_id_mask[index] ^= bit; |
208 | } else { | ||
209 | ACPI_ERROR((AE_INFO, | ||
210 | "Release of non-allocated owner_id: %2.2X", | ||
211 | owner_id + 1)); | ||
163 | } | 212 | } |
164 | 213 | ||
165 | (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); | 214 | (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); |
@@ -790,109 +839,97 @@ u8 acpi_ut_generate_checksum(u8 * buffer, u32 length) | |||
790 | 839 | ||
791 | /******************************************************************************* | 840 | /******************************************************************************* |
792 | * | 841 | * |
793 | * FUNCTION: acpi_ut_get_resource_end_tag | 842 | * FUNCTION: acpi_ut_error, acpi_ut_warning, acpi_ut_info |
794 | * | 843 | * |
795 | * PARAMETERS: obj_desc - The resource template buffer object | 844 | * PARAMETERS: module_name - Caller's module name (for error output) |
845 | * line_number - Caller's line number (for error output) | ||
846 | * Format - Printf format string + additional args | ||
796 | * | 847 | * |
797 | * RETURN: Pointer to the end tag | 848 | * RETURN: None |
798 | * | 849 | * |
799 | * DESCRIPTION: Find the END_TAG resource descriptor in a resource template | 850 | * DESCRIPTION: Print message with module/line/version info |
800 | * | 851 | * |
801 | ******************************************************************************/ | 852 | ******************************************************************************/ |
802 | 853 | ||
803 | u8 *acpi_ut_get_resource_end_tag(union acpi_operand_object * obj_desc) | 854 | void ACPI_INTERNAL_VAR_XFACE |
855 | acpi_ut_error(char *module_name, u32 line_number, char *format, ...) | ||
804 | { | 856 | { |
805 | u8 buffer_byte; | 857 | va_list args; |
806 | u8 *buffer; | ||
807 | u8 *end_buffer; | ||
808 | 858 | ||
809 | buffer = obj_desc->buffer.pointer; | 859 | acpi_os_printf("ACPI Error (%s-%04d): ", module_name, line_number); |
810 | end_buffer = buffer + obj_desc->buffer.length; | ||
811 | 860 | ||
812 | while (buffer < end_buffer) { | 861 | va_start(args, format); |
813 | buffer_byte = *buffer; | 862 | acpi_os_vprintf(format, args); |
814 | if (buffer_byte & ACPI_RDESC_TYPE_MASK) { | 863 | acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); |
815 | /* Large Descriptor - Length is next 2 bytes */ | 864 | } |
816 | 865 | ||
817 | buffer += ((*(buffer + 1) | (*(buffer + 2) << 8)) + 3); | 866 | void ACPI_INTERNAL_VAR_XFACE |
818 | } else { | 867 | acpi_ut_exception(char *module_name, |
819 | /* Small Descriptor. End Tag will be found here */ | 868 | u32 line_number, acpi_status status, char *format, ...) |
869 | { | ||
870 | va_list args; | ||
820 | 871 | ||
821 | if ((buffer_byte & ACPI_RDESC_SMALL_MASK) == | 872 | acpi_os_printf("ACPI Exception (%s-%04d): %s, ", module_name, |
822 | ACPI_RDESC_TYPE_END_TAG) { | 873 | line_number, acpi_format_exception(status)); |
823 | /* Found the end tag descriptor, all done. */ | ||
824 | 874 | ||
825 | return (buffer); | 875 | va_start(args, format); |
826 | } | 876 | acpi_os_vprintf(format, args); |
877 | acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); | ||
878 | } | ||
827 | 879 | ||
828 | /* Length is in the header */ | 880 | void ACPI_INTERNAL_VAR_XFACE |
881 | acpi_ut_warning(char *module_name, u32 line_number, char *format, ...) | ||
882 | { | ||
883 | va_list args; | ||
829 | 884 | ||
830 | buffer += ((buffer_byte & 0x07) + 1); | 885 | acpi_os_printf("ACPI Warning (%s-%04d): ", module_name, line_number); |
831 | } | 886 | |
832 | } | 887 | va_start(args, format); |
888 | acpi_os_vprintf(format, args); | ||
889 | acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); | ||
890 | } | ||
891 | |||
892 | void ACPI_INTERNAL_VAR_XFACE | ||
893 | acpi_ut_info(char *module_name, u32 line_number, char *format, ...) | ||
894 | { | ||
895 | va_list args; | ||
833 | 896 | ||
834 | /* End tag not found */ | 897 | acpi_os_printf("ACPI (%s-%04d): ", module_name, line_number); |
835 | 898 | ||
836 | return (NULL); | 899 | va_start(args, format); |
900 | acpi_os_vprintf(format, args); | ||
901 | acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); | ||
837 | } | 902 | } |
838 | 903 | ||
839 | /******************************************************************************* | 904 | /******************************************************************************* |
840 | * | 905 | * |
841 | * FUNCTION: acpi_ut_report_error | 906 | * FUNCTION: acpi_ut_report_error, Warning, Info |
842 | * | 907 | * |
843 | * PARAMETERS: module_name - Caller's module name (for error output) | 908 | * PARAMETERS: module_name - Caller's module name (for error output) |
844 | * line_number - Caller's line number (for error output) | 909 | * line_number - Caller's line number (for error output) |
845 | * component_id - Caller's component ID (for error output) | ||
846 | * | 910 | * |
847 | * RETURN: None | 911 | * RETURN: None |
848 | * | 912 | * |
849 | * DESCRIPTION: Print error message | 913 | * DESCRIPTION: Print error message |
850 | * | 914 | * |
915 | * Note: Legacy only, should be removed when no longer used by drivers. | ||
916 | * | ||
851 | ******************************************************************************/ | 917 | ******************************************************************************/ |
852 | 918 | ||
853 | void acpi_ut_report_error(char *module_name, u32 line_number, u32 component_id) | 919 | void acpi_ut_report_error(char *module_name, u32 line_number) |
854 | { | 920 | { |
855 | 921 | ||
856 | acpi_os_printf("%8s-%04d: *** Error: ", module_name, line_number); | 922 | acpi_os_printf("ACPI Error (%s-%04d): ", module_name, line_number); |
857 | } | 923 | } |
858 | 924 | ||
859 | /******************************************************************************* | 925 | void acpi_ut_report_warning(char *module_name, u32 line_number) |
860 | * | ||
861 | * FUNCTION: acpi_ut_report_warning | ||
862 | * | ||
863 | * PARAMETERS: module_name - Caller's module name (for error output) | ||
864 | * line_number - Caller's line number (for error output) | ||
865 | * component_id - Caller's component ID (for error output) | ||
866 | * | ||
867 | * RETURN: None | ||
868 | * | ||
869 | * DESCRIPTION: Print warning message | ||
870 | * | ||
871 | ******************************************************************************/ | ||
872 | |||
873 | void | ||
874 | acpi_ut_report_warning(char *module_name, u32 line_number, u32 component_id) | ||
875 | { | 926 | { |
876 | 927 | ||
877 | acpi_os_printf("%8s-%04d: *** Warning: ", module_name, line_number); | 928 | acpi_os_printf("ACPI Warning (%s-%04d): ", module_name, line_number); |
878 | } | 929 | } |
879 | 930 | ||
880 | /******************************************************************************* | 931 | void acpi_ut_report_info(char *module_name, u32 line_number) |
881 | * | ||
882 | * FUNCTION: acpi_ut_report_info | ||
883 | * | ||
884 | * PARAMETERS: module_name - Caller's module name (for error output) | ||
885 | * line_number - Caller's line number (for error output) | ||
886 | * component_id - Caller's component ID (for error output) | ||
887 | * | ||
888 | * RETURN: None | ||
889 | * | ||
890 | * DESCRIPTION: Print information message | ||
891 | * | ||
892 | ******************************************************************************/ | ||
893 | |||
894 | void acpi_ut_report_info(char *module_name, u32 line_number, u32 component_id) | ||
895 | { | 932 | { |
896 | 933 | ||
897 | acpi_os_printf("%8s-%04d: *** Info: ", module_name, line_number); | 934 | acpi_os_printf("ACPI (%s-%04d): ", module_name, line_number); |
898 | } | 935 | } |