aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/utilities/utmisc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/utilities/utmisc.c')
-rw-r--r--drivers/acpi/utilities/utmisc.c147
1 files changed, 71 insertions, 76 deletions
diff --git a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c
index 2ce872d75890..a77ffcd5570f 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")
63acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id) 63acpi_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");
@@ -82,31 +84,66 @@ 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 */
101
102 break;
103 }
104
105 if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) {
106 /*
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);
86 115
87 for (i = 0; i < 64; i++) { 116 /*
88 if (!(acpi_gbl_owner_id_mask & (1ULL << i))) { 117 * Construct encoded ID from the index and bit position
89 ACPI_DEBUG_PRINT((ACPI_DB_VALUES, 118 *
90 "Current owner_id mask: %16.16LX New ID: %2.2X\n", 119 * Note: Last [j].k (bit 255) is never used and is marked
91 acpi_gbl_owner_id_mask, 120 * permanently allocated (prevents +1 overflow)
92 (unsigned int)(i + 1))); 121 */
122 *owner_id =
123 (acpi_owner_id) ((k + 1) + ACPI_MUL_32(j));
93 124
94 acpi_gbl_owner_id_mask |= (1ULL << i); 125 ACPI_DEBUG_PRINT((ACPI_DB_VALUES,
95 *owner_id = (acpi_owner_id) (i + 1); 126 "Allocated owner_id: %2.2X\n",
96 goto exit; 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_REPORT_ERROR(("Could not allocate new owner_id (255 max), AE_OWNER_ID_LIMIT\n"));
110 147
111 exit: 148 exit:
112 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); 149 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
@@ -123,7 +160,7 @@ acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
123 * control method or unloading a table. Either way, we would 160 * control method or unloading a table. Either way, we would
124 * ignore any error anyway. 161 * ignore any error anyway.
125 * 162 *
126 * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 64 163 * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255
127 * 164 *
128 ******************************************************************************/ 165 ******************************************************************************/
129 166
@@ -131,6 +168,8 @@ void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
131{ 168{
132 acpi_owner_id owner_id = *owner_id_ptr; 169 acpi_owner_id owner_id = *owner_id_ptr;
133 acpi_status status; 170 acpi_status status;
171 acpi_native_uint index;
172 u32 bit;
134 173
135 ACPI_FUNCTION_TRACE_U32("ut_release_owner_id", owner_id); 174 ACPI_FUNCTION_TRACE_U32("ut_release_owner_id", owner_id);
136 175
@@ -140,7 +179,7 @@ void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
140 179
141 /* Zero is not a valid owner_iD */ 180 /* Zero is not a valid owner_iD */
142 181
143 if ((owner_id == 0) || (owner_id > 64)) { 182 if (owner_id == 0) {
144 ACPI_REPORT_ERROR(("Invalid owner_id: %2.2X\n", owner_id)); 183 ACPI_REPORT_ERROR(("Invalid owner_id: %2.2X\n", owner_id));
145 return_VOID; 184 return_VOID;
146 } 185 }
@@ -156,10 +195,18 @@ void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
156 195
157 owner_id--; 196 owner_id--;
158 197
198 /* Decode ID to index/offset pair */
199
200 index = ACPI_DIV_32(owner_id);
201 bit = 1 << ACPI_MOD_32(owner_id);
202
159 /* Free the owner ID only if it is valid */ 203 /* Free the owner ID only if it is valid */
160 204
161 if (acpi_gbl_owner_id_mask & (1ULL << owner_id)) { 205 if (acpi_gbl_owner_id_mask[index] & bit) {
162 acpi_gbl_owner_id_mask ^= (1ULL << owner_id); 206 acpi_gbl_owner_id_mask[index] ^= bit;
207 } else {
208 ACPI_REPORT_ERROR(("Release of non-allocated owner_id: %2.2X\n",
209 owner_id + 1));
163 } 210 }
164 211
165 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); 212 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
@@ -790,59 +837,10 @@ u8 acpi_ut_generate_checksum(u8 * buffer, u32 length)
790 837
791/******************************************************************************* 838/*******************************************************************************
792 * 839 *
793 * FUNCTION: acpi_ut_get_resource_end_tag
794 *
795 * PARAMETERS: obj_desc - The resource template buffer object
796 *
797 * RETURN: Pointer to the end tag
798 *
799 * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
800 *
801 ******************************************************************************/
802
803u8 *acpi_ut_get_resource_end_tag(union acpi_operand_object * obj_desc)
804{
805 u8 buffer_byte;
806 u8 *buffer;
807 u8 *end_buffer;
808
809 buffer = obj_desc->buffer.pointer;
810 end_buffer = buffer + obj_desc->buffer.length;
811
812 while (buffer < end_buffer) {
813 buffer_byte = *buffer;
814 if (buffer_byte & ACPI_RDESC_TYPE_MASK) {
815 /* Large Descriptor - Length is next 2 bytes */
816
817 buffer += ((*(buffer + 1) | (*(buffer + 2) << 8)) + 3);
818 } else {
819 /* Small Descriptor. End Tag will be found here */
820
821 if ((buffer_byte & ACPI_RDESC_SMALL_MASK) ==
822 ACPI_RDESC_TYPE_END_TAG) {
823 /* Found the end tag descriptor, all done. */
824
825 return (buffer);
826 }
827
828 /* Length is in the header */
829
830 buffer += ((buffer_byte & 0x07) + 1);
831 }
832 }
833
834 /* End tag not found */
835
836 return (NULL);
837}
838
839/*******************************************************************************
840 *
841 * FUNCTION: acpi_ut_report_error 840 * FUNCTION: acpi_ut_report_error
842 * 841 *
843 * PARAMETERS: module_name - Caller's module name (for error output) 842 * PARAMETERS: module_name - Caller's module name (for error output)
844 * line_number - Caller's line number (for error output) 843 * line_number - Caller's line number (for error output)
845 * component_id - Caller's component ID (for error output)
846 * 844 *
847 * RETURN: None 845 * RETURN: None
848 * 846 *
@@ -850,10 +848,10 @@ u8 *acpi_ut_get_resource_end_tag(union acpi_operand_object * obj_desc)
850 * 848 *
851 ******************************************************************************/ 849 ******************************************************************************/
852 850
853void acpi_ut_report_error(char *module_name, u32 line_number, u32 component_id) 851void acpi_ut_report_error(char *module_name, u32 line_number)
854{ 852{
855 853
856 acpi_os_printf("%8s-%04d: *** Error: ", module_name, line_number); 854 acpi_os_printf("ACPI Error (%s-%04d): ", module_name, line_number);
857} 855}
858 856
859/******************************************************************************* 857/*******************************************************************************
@@ -862,7 +860,6 @@ void acpi_ut_report_error(char *module_name, u32 line_number, u32 component_id)
862 * 860 *
863 * PARAMETERS: module_name - Caller's module name (for error output) 861 * PARAMETERS: module_name - Caller's module name (for error output)
864 * line_number - Caller's line number (for error output) 862 * line_number - Caller's line number (for error output)
865 * component_id - Caller's component ID (for error output)
866 * 863 *
867 * RETURN: None 864 * RETURN: None
868 * 865 *
@@ -870,11 +867,10 @@ void acpi_ut_report_error(char *module_name, u32 line_number, u32 component_id)
870 * 867 *
871 ******************************************************************************/ 868 ******************************************************************************/
872 869
873void 870void acpi_ut_report_warning(char *module_name, u32 line_number)
874acpi_ut_report_warning(char *module_name, u32 line_number, u32 component_id)
875{ 871{
876 872
877 acpi_os_printf("%8s-%04d: *** Warning: ", module_name, line_number); 873 acpi_os_printf("ACPI Warning (%s-%04d): ", module_name, line_number);
878} 874}
879 875
880/******************************************************************************* 876/*******************************************************************************
@@ -883,7 +879,6 @@ acpi_ut_report_warning(char *module_name, u32 line_number, u32 component_id)
883 * 879 *
884 * PARAMETERS: module_name - Caller's module name (for error output) 880 * PARAMETERS: module_name - Caller's module name (for error output)
885 * line_number - Caller's line number (for error output) 881 * line_number - Caller's line number (for error output)
886 * component_id - Caller's component ID (for error output)
887 * 882 *
888 * RETURN: None 883 * RETURN: None
889 * 884 *
@@ -891,8 +886,8 @@ acpi_ut_report_warning(char *module_name, u32 line_number, u32 component_id)
891 * 886 *
892 ******************************************************************************/ 887 ******************************************************************************/
893 888
894void acpi_ut_report_info(char *module_name, u32 line_number, u32 component_id) 889void acpi_ut_report_info(char *module_name, u32 line_number)
895{ 890{
896 891
897 acpi_os_printf("%8s-%04d: *** Info: ", module_name, line_number); 892 acpi_os_printf("ACPI (%s-%04d): ", module_name, line_number);
898} 893}